3
我一直在上面拉下面的代碼片段我的頭髮 - 這是syntatically正確的。但是我不斷收到以下錯誤,當我把它放在服務器上:PHP DOM文檔實例語法錯誤
Parse error: syntax error, unexpected T_VARIABLE in /home/scripts/temp.php5 on line 3
3號線:
Line 3 = $dom = new DOMDocument();
任何想法我可能做錯了什麼?
<?php
// new dom object
$dom = new DOMDocument();
//load the html
$html = $dom->loadHTMLFile('<HTML><A HREF="ss">asd</A>');
//discard white space
$dom->preserveWhiteSpace = false;
//the table by its tag name
$tables = $dom->getElementsByTagName('table');
//get all rows from the table
$rows = $tables->item(0)->getElementsByTagName('tr');
// loop over the table rows
foreach ($rows as $row)
{
// get each column by tag name
$cols = $row->getElementsByTagName('td');
// echo the values
echo $cols->item(0)->nodeValue.'';
echo $cols->item(1)->nodeValue.'';
echo $cols->item(2)->nodeValue;
}
?>
你的錯誤可能來自於你的DOM文檔實例前行。可能的話,在這行之前有一個缺少分號或未封閉的引用或一些這樣的東西。 –
很多時候,您應該查看PHP報告錯誤的行之前的行。 –
以前沒有行 - 這是php文件中的唯一片段.. – ChicagoDude