使用PHP Simple HTML DOM解析器的奇怪错误 [英] Weird error using PHP Simple HTML DOM parser
问题描述
我正在使用此库(PHP简单HTML DOM解析器)来解析链接,这是代码:
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:
致命错误:在非对象中调用成员函数find() /var/www/vhosts/efamous.de/subdomains/sandbox/httpdocs/getNewTrusts.php 在第25行
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
(第25行是foreach循环),奇怪的是它(至少在表面上)正确地输出了所有内容,但我仍然遇到该错误,无法弄清原因.
(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.
推荐答案
此错误通常表示$ html不是对象.
This error usually means that $html isn't an object.
奇怪的是,您说这似乎行得通.如果输出$ html会怎样? 我以为网址不可用,而$ html为空.
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.
看起来这可能是解析器中的错误.有人提交了 bug 并添加了一个检查他的代码以解决该问题.
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.
这篇关于使用PHP Simple HTML DOM解析器的奇怪错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!