• Sign in to Neowin Faster!

    Create an account on Neowin to contribute and support the site.

  • 0
Sign in to follow this  

[php] Preg_Match

Question

fock neow1n    0

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.

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0
fock neow1n    0

lol, .._all did the trick thanks.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.