Extract data php string

I used file_get_contents () to get the source code of the site into one string variable.

The source contains many lines that look like this: <td align="center"><a href="somewebsite.com/something">12345</a></td>

(and many lines that do not look like this). I want to extract all idnumber (12345 above) and put them in an array. How can i do this? I suppose I want to use some kind of regular expressions and then use the preg_match_all () function, but I'm not sure how ...

+2
source share
2 answers

Try the following:

preg_match('/>[0-9]+<\/a><\/td>/', $str, $matches);
for($i = 0;$i<sizeof($matches);$i++)
 $values[] = $matches[$i];
+1
source
+4

All Articles