Jump to content


This topic is now archived and is closed to further replies.


regex, preg_match help

Recommended Posts

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
[code]<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">[/code]

height, weight, birthdate html to parse:
[code]        <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

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.