从HTML代码解析数字时的空白页使用'PHP简单的HTML DOM解析器'

问题描述:

我使用PHP Simple HTML DOM Parser而我有一些HTML代码,从它我想提取第一个数字出现,在这个例子中'735438' :从HTML代码解析数字时的空白页使用'PHP简单的HTML DOM解析器'

<!-- Some Tds without onclick atribute -> 
<td onclick="StatsAnnonce ('735438');" style="CURSOR:pointer;" onmouseover="return escape('<img src=/images/icon_stats.gif border=0 width=13 height=14> <b>Statistiques de cette annonce</b><li>Affichages des détails annonce</li><li>Classement par mois et par pays.</li>');">&nbsp;&nbsp;<img src="/images/icon_stats.gif" border="0" width="13" height="14" alt="Statistique annonce">&nbsp;Stats&nbsp;</td> 
<td onclick="ModifAnnonce ('735438','1','302528');" style="CURSOR:pointer;" onmouseover="return escape('<img src=/images/button_edit.gif border=0 width=13 height=14> <b>Editer cette annonce</b><li>Modifier : titre, texte, prix</li><li>Ajouter/Supprimer des photos</li>');">&nbsp;&nbsp;<img src="/images/button_edit.gif" border="0" width="13" height="14" alt="Modifier l'annonce">&nbsp;Modif&nbsp;</td> 
<td onclick="ProlongerAnnonce ('735438');" style="CURSOR:pointer;" onmouseover="return escape('<img src=/images/button_calendar.gif border=0 width=14 height=14> <b>Renouveler cette annonce</b>');"><img src="/images/button_calendar.gif" border="0" width="14" height="14" alt="Renouveler l'annonce">&nbsp;Renouv&nbsp;</td> 
<td onclick="DeleteAnnonce('735438','06/08/2012 00:50','302528','Bon appart s+1');" style="CURSOR:pointer;" onmouseover="return escape('<img src=/images/button_trash.gif border=0 width=13 height=14> <b>Supprimer cette annonce</b>');"><img src="/images/button_trash.gif" border="0" width="13" height="14" alt="Supprimer l'annonce">&nbsp;Suppr&nbsp;</td> 

我有这个代码试图(根据文档的说明),但不工作:

$html = str_get_html('page.html'); 

// Find all <td> with the 'onclick' as attribute 
$ret = $html->find('td[onclick]'); 


// Find just all <td> 
$ret = $html->find('td'); 


foreach($ret as $val) 
{ 
echo $val."<br/>"; 
} 

结果只是一个没有代码的空白页... 我新太HTML DOM解析器,请如果有人曾经工作过这个库帮我...

在此先感谢

首先,我要确保你实际上是在文档中读取(我敢肯定你不是在这一点上)。您应该使用:

$html = file_get_html('page.html'); // This! 
//$html = str_get_html('page.html'); // Not this! 

假设你想从中提取onclick属性信息,看来你应该在你的foreach循环使用:

echo $val->onclick . "<br/>"; // This! 
//echo $val."<br/>"; //Not this! 

$val仍然是一个HTML元素这一点 - 我不确定你会得到什么,如果你回应它,但我猜这不是你想要的。