[英]PHP parsing html with DOM
我正在尝试使以下代码正常工作,以便我了解我在大型项目中的工作。 在大多数情况下,我只是在尝试确保可以按其标签抓取元素。 该代码似乎在“ $ html = new simple_html_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();
?>
simple_html_dom.php
文件是否实际退出并加载了? 您可能要编写include
类似于:
<?php
if(!@file_exists('./simple_html_dom.php') )
{
echo 'can not include: simple_html_dom.php';
die();
}
else
{
include('./simple_html_dom.php');
}
?>
因此,服务器上的PHP解析器将让您知道是否存在问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.