i trying detect couple things url.
- is valid
does have specific div in it
$url = 'http://www.google.com/aasdsasdfafddsgsagf'; $dom = new domdocument; libxml_use_internal_errors(true); $request = $dom->loadhtmlfile($url); $domxpath = new domxpath($dom); $title = $domxpath->query("//span[@class='bluebar']") if(!$request || $title->length == 0){ echo 'failed!!'; }
i trying conditions:
if page loads , does not have div - nothing.
if page not load - nothing.
right getting error stops comes after running properly.
error:
warning: domdocument::loadhtmlfile(http://www.google.com/aasdsasdfafddsgsagf): failed open stream: http request failed! http/1.0 404 not found in... i still echo 'failed!!'.
please help!!
if understand question correctly, problem can solved suppressing warning. can done affixing $dom->loadhtmlfile($url) error control operator @.
$request = @$dom->loadhtmlfile($url); in example there missing semicolon after setting $title. causes php parse error. code want:
$url = 'http://www.google.com/aasdsasdfafddsgsagf'; $dom = new domdocument; libxml_use_internal_errors(true); $request = $dom->loadhtmlfile($url); // $request === false $domxpath = new domxpath($dom); $title = $domxpath->query("//span[@class='bluebar']"); if(!$request || $title->length == 0){ echo 'failed!!'; }
Comments
Post a Comment