|
Posted by Anthony David Adams on 09/28/14 11:43
I've been trying to write this off and on for a while now, and in the
process, have been trying to figure out preg_match. This is a very
simple, straightforward problem..
I am writing a peice of PHP to read in a webpage that changes each
week, and pull out the ranking for a college ultimate frisbee team.
I have no trouble reading the webpage into string variable, but I am
uncertain on the proper preg_match syntax to extract the rank (and
eventually other information such as record.
The end goal is to be able to pass a team name to the script, and have
it return the rank and record of the team.. For now, I am just focused
on getting the rank.
The raw page is here :
http://www4.upa.org/scores/scores.cgi?div=18&page=22
here is an excerpt of the source code relevant to the team / rank:
<<<
<tr style='cursor: pointer; cursor: hand'
onmouseover=this.style.backgroundColor='ff8888'
onmouseout=this.style.backgroundColor=''
onclick='window.location.href="scores.cgi?div=18&page=3&team=1190"'><td
align=right>2) <td align=center>1587<td><u>Wisconsin<td
align=center>29-2<td align=center>CN<td align=center>LS
<<<
So, if you know what you're looking for, you'll see that Wisconsin is
ranked 2nd, their power rating is 1587, the record is 29-2 and they are
in the CN region of the country.
The important info is that Wisconsin is a unique team name, so it will
only appear once on the page.
The rank is found in this snippet : &team=1190"'><td
align=right>*******2******) <td >
The rank can range from 1 - 400.
I tried using the following code, but it didn't work:
<?PHP
$page =
file_get_contents('http://www4.upa.org/scores/scores.cgi?div=18&page=22');
preg_match('/<td align=right>(.*?)\) <td
align=center>1587<td><u>Wisconsin/',$page,$rank);
print_r($rank);
?>
I'm reading the file in fine, but i think it is finding another
instance of the <td align> etc, then seeing the . and including all the
the stuff in the middle... i need to specify a length of the subject
perhaps...
PLEASE HELP!
Either syntaxt help, a differant coding approach altogether, or just
write the line of code for me ;)
THANKS!
Anthony
Navigation:
[Reply to this message]
|