Jump to content

php strpos problem

- - - - -

  • Please log in to reply
No replies to this topic

#1
dmanjrod

dmanjrod

    Newbie

  • Members
  • Pip
  • 7 posts
I have a script that's fetching a page from a site using cURL and im trying to cut it up row by row then extracting what i need and removing that row. The problem is, sometimes it will give me the correct position of an item and sometimes it wont depending on what row, it alternates.

im trying to use one of these pages: Game Server Search, Player Search, Server List, Stats, and Rankings

the code im using is:

while (strpos($contents, '<tr>'))

{

	$start = strpos($contents, '<tr>');

	$end = strpos($contents, '</tr>', $start) + 5;

	$rstring = substr($contents, $start, $end - $start);

	$contents = str_replace($rstring, '', $contents);

	//nameee

        $start = strpos($rstring, '[clantag]');

	$end = strpos($rstring, '</a>', $start);

	$name= trim(substr($rstring, $start, $end - $start));

	echo $name . '<br/>';

        //players

	$search = '<td class="c05 item_bgcolor_even">';

        $start = (strpos($rstring, $search) + strlen($search));

	$end = strpos($rstring, "</td>", $start);

	$players= trim(substr($rstring, $start, ($end - $start)));

	echo $players . '<br />';

	$map;

	$curPlayers;

	$maxPlayers;

	$ip;

}


It gets the server name correctly but when it comes to players, one line i get them and the other I get lor_odd"> 1230.

Edit: I just dropped this and found a better way using DOMParser instead.

Edited by dmanjrod, 18 June 2011 - 09:22 AM.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users