Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 381
Tsundoku Avatar asked Jul 26 '11 15:07

Tsundoku


2 Answers

The reason for this error is: the simple HTML DOM does not return the object if the size of the response from url is greater than 600000.
You can void it by changing the simple_html_dom.php file. Remove strlen($contents) > MAX_FILE_SIZE from the if condition of the file_get_html function.
This will solve your issue.

like image 175
Sagar Shetty Avatar answered Sep 21 '22 17:09

Sagar Shetty


You just need to increase CONSTANT MAX_FILE_SIZE in file simple_html_dom.php.

For example:

define('MAX_FILE_SIZE', 999999999999999);
like image 22
LAMPHONGPAUL Avatar answered Sep 21 '22 17:09

LAMPHONGPAUL