-1

How to get data from this ?

<td align="right" width="100"><span class="statsTopHi">1,234,567</span></td>

I need to get statsTopHi data? but dont know how to do it, i'm new to php and dont know anything about curl.

<?php
    $handle = curl_init();
    curl_setopt($handle, CURLOPT_URL, "my url");
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
    $html = curl_exec($handle);
    curl_close($handle);

   $DOM = new DOMDocument;
   $DOM->loadHTML($html);

   //get all span
   $items = $DOM->getElementsByTagName('span');

   //display all span text
   for ($i = 0; $i < $items->length; $i++)
        echo $items->item($i)->nodeValue . "<br/>";
?>

Using this i parse all span content, but need to get only class="statsTopHi"

  • 1
    Have a look at the "Related" column on the right, for example http://stackoverflow.com/q/6829760/427545. `curl` is about retrieving data, but to parse this data you need regular expressions (if the format is well-known and not subject to change) or a full HTML parser. – Lekensteyn May 11 '13 at 13:50

2 Answers2

0
preg_match( '/<span class="statsTopHi">(.+?)</span>/i', $html, $mat );
print_r( $mat );

OR

preg_match_all( '/<span class="statsTopHi">(.+?)</span>/i', $html, $mat );
print_r( $mat );

Depending on how many spans you want.

Kohjah Breese
  • 4,008
  • 6
  • 32
  • 48
0

Find much easier way to parse item by class using Ganon

parent->getPlainText(); ?>