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