Jump to content


regex, preg_match help

  • Please log in to reply
No replies to this topic

#1 esiason14

  • Members
  • PipPipPip
  • Advanced Member
  • 58 posts

Posted 18 March 2006 - 02:17 AM

I'm trying to pull data for a few players from another site. This is NOT for commercial use..Anyway, I want to pull the following info:

Player name, jersey number, position, team, height, weight, birthdate...and then later on their career stats.

So far this is what I have (this only works for the player name, jersey number and position so far):


for($count=6619;$count<=6619;$count++) {

/*** Load the page here ***/

$input = file_get_contents("http://sports.yahoo.com/mlb/players/{$count}/career");

// *** Finding the info, First Name, Last Name, Jersey Number, Position ***/

preg_match('@(?<="yspsctnhdln"\>)([^<]+)<\/span>\s*#(\d+)\s([^<]+)\s([^<]+)\s@ism', $input, $info);

$name = explode(" ", $info[1]);
$jersey = trim($info[2], "  |  ");
$initialposition = explode("/", $info[3]);
$position = trim($initialposition[0], "  |  ");
$team = explode(" ", $info[4]);

preg_match('@<span class="yspscores" style="line-height:140%;">([.]+)\sWeight:([^<]+)<br>\s</span>@i', $input, $match);

$height = explode("Height:", $match[1]);
$weight = explode("     ", $match[2]);

echo '<table>';
echo '</table>';

I know I messed up the heigh, weight and team regex,etc. I was hoping someone coulc point me in the right direction. Heres the html:

Player name, jersey , position and team html to parse
<b><span class="yspsctnhdln">Albert Pujols</span>
            #5   |  
             First Base/Left Field   |  
      <a href="http://us.lrd.yahoo.com/_ylt=AiO5aw3ziz_LLaUn2BcY.qiFCLcF/SIG=11ajpqctg/**http%3a//sports.yahoo.com/mlb/teams/stl" >St. Louis Cardinals</a></b></td>
             <td align="right" class="yspgens">

height, weight, birthdate html to parse:
        <span class="yspscores" style="line-height:140%;">
      Height: 6-3      
      Weight: 225<br>
      Bats: R      
      Throws: R<br>
      Born: Jan 16, 1980 - Santo Domingo, Dominican Republic<br>

      College: Maple Woods (MO) CC<br>

      Draft: 1999 - 13th round by the St. Louis Cardinals

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users