Tsundoku Tsundoku - 28 days ago 13
PHP Question

Weird error using PHP Simple HTML DOM parser

I am using this library (PHP Simple HTML DOM parser) to parse a link, here's the code:

function getSemanticRelevantKeywords($keyword){
$results = array();
$html = file_get_html("http://www.semager.de/api/keyword.php?q=". urlencode($keyword) ."&lang=de&out=html&count=2&threshold=");
foreach($html->find('span') as $e){
$results[] = $e->plaintext;
}
return $results;
}


but I am getting this error when I output the results:


Fatal error: Call to a member function find() on a non-object in
/var/www/vhosts/efamous.de/subdomains/sandbox/httpdocs/getNewTrusts.php
on line 25


(line 25 is the foreach loop), the odd thing is that it outputs everything (at least seemingly) correctly but I still get that error and can't figure out why.

Jim Jim
Answer

This error usually means that $html isn't an object.

It's odd that you say this seems to work. What happens if you output $html? I'd imagine that the url isn't available and that $html is null.

Edit: Looks like this may be an error in the parser. Someone has submitted a bug and added a check in his code as a workaround.