I'm using PHP Simple HTML DOM Parser And I have some HTML codes that from it i want to extract the first number appear, in this example is '735438
':
<!-- 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>');"> <img src="/images/icon_stats.gif" border="0" width="13" height="14" alt="Statistique annonce"> Stats </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>');"> <img src="/images/button_edit.gif" border="0" width="13" height="14" alt="Modifier l'annonce"> Modif </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"> Renouv </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"> Suppr </td>
I have tried with this code(according to the doc instructions) but not working :
$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/>";
}
The result is just a blank page with no code... I'm newer too HTML DOM Parser, please if somewone have worked with this library help me...
Thanks in advance
First, I'd make sure that you're actually reading in the document (I'm pretty sure you're not at this point). You should be using:
$html = file_get_html('page.html'); // This!
//$html = str_get_html('page.html'); // Not this!
Assuming you're trying to extract information from the onclick
attribute, it seems you should use this in your foreach
loop:
echo $val->onclick . "<br/>"; // This!
//echo $val."<br/>"; //Not this!
$val
is still an html element at this point - I'm not sure what you'll get if you echo it out, but I'm guessing it's not what you're looking for.