PHP解析DOM与DOM

问题描述:

我想让下面的代码工作,以便我明白我在做一个大型项目。大多数情况下,我只是试图确保我可以通过标签获取元素。该代码似乎打破了“$ html = new simple_html_dom();”因为如果我对此发表评论,那么我会得到两份打印件。但是如果没有注释掉,屏幕上什么也没有显示。PHP解析DOM与DOM

<?php 
# create and load the HTML 

include('simple_html_dom.php'); 
print "hello "; 
$html = new simple_html_dom(); 

print "world" 
#$html->load("<html><body><p>Hello World!</p><p>We're here</p></body></html>"); 

# get an element representing the second paragraph 
#$element = $html->find("p"); 
# modify it 
#$element[1]->innertext .= " and we're here to stay."; 

# output it! 
#echo $html->save(); 
?> 
+1

你应该真的设置'error_reporting(E_ALL)'进行开发。 –

+0

而'ini_set('display_errors',true);'也是。 –

+1

如果您看到空白页面,则表示在某处出现错误,并且您在浏览器中禁用了显示错误。 您可以使用AlexZ建议的'display_errors'或查看服务器日志。日志的位置取决于你的系统,但对于Linux来说,开始寻找的好地方是'/ var/log/apache2/error.log'。 – pwaring

是否simple_html_dom.php文件实际退出并加载?您可能要编写include类似于:

<?php 
if([email protected]_exists('./simple_html_dom.php')) 
{ 
    echo 'can not include: simple_html_dom.php'; 
    die(); 
} 
else 
{ 
    include('./simple_html_dom.php'); 
} 
?> 

所以在服务器上的PHP解析器将让你知道,如果出现了问题。

+0

得到它的工作。多谢你们。问题很简单,我没有在同一个目录下的simple_html_dom.php。并把错误检查指出了。 – user3672063

+0

或者使用'require'而不是'include',因为它会检查文件是否存在并且可读,如果不是,则会发生致命错误。 – pwaring