[英]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.