我正在使用 PHP Dom Parser 库,我有一个复杂的 HTML 结构来解析:
<table width="640" style="color: #333333;">
<tbody><tr>
<td valign="top">
<font face="Arial,Helevetica,sans-serif">
<a href="http://forums.timezone.com/index.php?t=tree&goto=6577581&rid=0">20mm Omega SMP Bond Bracelet Ref. 1503-825- PRICE DROP</a><br>
<font size="-1" color="#999999">Sales Corner - <a href="http://forums.timezone.com/index.php?t=usrinfo&id=462&rid=0">The Bigwatch Guy</a></font><font size="-1" color="#999999"> - Aug 7, 2013</font><br>
<font size="-1">20mm OMEGA SEAMASTER PROFESSIONAL "BOND" BRACELET REF. 1503-825. All s/s genuine Bond bracelet in excellent condition. The bracelet is 6.6 inches long...</font>
<br>
<br>
</font></td>
</tr>
<tr>
<td valign="top">
<font face="Arial,Helevetica,sans-serif">
<a href="http://forums.timezone.com/index.php?t=tree&goto=6577577&rid=0">Longines Lindbergh Hour Angle Chronograph- PRICE DROP</a><br>
<font size="-1" color="#999999">Sales Corner - <a href="http://forums.timezone.com/index.php?t=usrinfo&id=462&rid=0">The Bigwatch Guy</a></font><font size="-1" color="#999999"> - Aug 7, 2013</font><br>
<font size="-1">42mm (not counting the crown) LONGINES LINDBERGH HOUR ANGLE AUTOMATIC CHRONOGRAPH W/ COMPLETE BOXSET AND PAPERS - NEARMINT PLUS CONDITION. The strap h...</font>
<br>
<br>
</font></td>
</tr>
</table>
我正在尝试获取 href 属性包含goto
字符串的所有锚标记,我尝试使用以下代码:
<?php
include("ganon.php");
$html = file_get_dom('http://forums.timezone.com/search/?q=Public+Forum&f=4&s=0');
$c=1;
if( count($html("table[width='640']"))>0 ){
foreach($html("a[href=*goto]") as $elm){
echo $c.')'.$elm->href.'<br/>';
$c++;
}
}
?>
上面的代码抛出了这个通知:Notice: Expected identifier at 7! in D:\xampp\htdocs\govberg\ganon.php on line 2196
没有其他输出。