0

I have table like this -> http://jsfiddle.net/jurisKaste/FvgeQ/

And I need to get array of all those numbers from id column... im using php code and I have so far this piece of code from here. i must use php only! Get number from a string

how could i modify this regexp to get a bit readable array ? so the complete code look like this


    $data = str_replace(",", ".", $data); // $data is that html code from fiddle!
    preg_match_all("/[+-]?\d+[\d\.Ee+]*/", $data, $matches);
    var_dump($matches);

edit: what about this ?


    $data = str_replace(",", "", $data);
    preg_match_all("/[0-9]{5,6}/",$data,$matches);
    print var_dump($matches);

it works for me...

Community
  • 1
  • 1
wolf3d
  • 112
  • 2
  • 11
  • 2
    http://www.codinghorror.com/blog/2009/11/parsing-html-the-cthulhu-way.html – VolkerK Aug 05 '11 at 08:00
  • Don't parse HTML wil REGEX, it's evil. Consider this [Excellent Answer](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454) someone else wrote. – Madara's Ghost Aug 13 '11 at 07:22

3 Answers3

2

Try this, it looks for the first td after each <tr then gets the number in between the <td> and </td>

preg_match_all("/\<tr.+?td.+?\>([\d,]+?)\</s",$string,$matches);
print "<pre>"; var_dump($matches); print "</pre>";
ace
  • 7,293
  • 3
  • 23
  • 28
  • it's data from google spreadsheet structured query, it gives this id with comma... so i cut it out and use this regexp pattern... and it works... in example i have 6 digit id, but it can be 5 digit too... that's why i wrote {5,6} $data = str_replace(",", "", $data); preg_match_all("/[0-9]{5,6}/",$data,$matches); print "
    "; var_dump($matches); print "
    ";
    – wolf3d Aug 05 '11 at 19:26
0

try it

$xml=new SimpleXMLElement($data);
foreach($xml->tr as $tr){
    echo $tr->td[0];
}
RiaD
  • 46,822
  • 11
  • 79
  • 123
0
$data = str_replace(",", "", $data);
preg_match_all("/[0-9]{5,6}/",$data,$matches);
print var_dump($matches);
wolf3d
  • 112
  • 2
  • 11