fock neow1n Posted July 25, 2005 Share Posted July 25, 2005 Working on a script that retrieves the content of a page and takes out only parts I'm looking for with preg_match. It's working fine except that preg_match will only retrieve 1 result, but there are 2 things to retrieve. <tr> <td><b>Rank:</b></td> <td>2,120</td> </tr> <tr> <td><b>Army Size:</b></td> <td>2,250</td> </tr> function getStats( $url ) { $fr = fopen("$url", "r"); $fd = ""; do { $data = fread($fr, 8192); if (strlen($data) == 0) { break; } $fd .= $data; } while(true); //echo $fd; $start= strpos($fd, "<body>"); $finish= strpos($fd, "</body>"); $length= $finish-$start; $code=Substr($fd, $start, $length); echo $code; if(preg_match("/>[0-9].+<\/td>/i", $code, $matches)) { echo "Success<br>"; print_r($matches); } else { echo "Nope"; } } url is http://www.kingsofchaos.com/stats.php?id=2631570 the code gets all the content, there are 2 <TD>s and I only get 1 of them. Link to comment Share on other sites More sharing options...
0 briley Posted July 25, 2005 Share Posted July 25, 2005 Check out preg_match_all Link to comment Share on other sites More sharing options...
0 fock neow1n Posted July 25, 2005 Author Share Posted July 25, 2005 lol, .._all did the trick thanks. Link to comment Share on other sites More sharing options...
Question
fock neow1n
Working on a script that retrieves the content of a page and takes out only parts I'm looking for with preg_match. It's working fine except that preg_match will only retrieve 1 result, but there are 2 things to retrieve.
url is http://www.kingsofchaos.com/stats.php?id=2631570
the code gets all the content, there are 2 <TD>s
and I only get 1 of them.
Link to comment
Share on other sites
2 answers to this question
Recommended Posts