• 0

[php] Preg_Match


Question

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, "&lt;body&gt;");
$finish= strpos($fd, "&lt;/body&gt;");
$length= $finish-$start;
$code=Substr($fd, $start, $length);

echo $code;
if(preg_match("/&gt;[0-9].+&lt;\/td&gt;/i", $code, $matches))
{
	echo "Success&lt;br&gt;";
	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

2 answers to this question

Recommended Posts

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.