esiason14 Posted March 18, 2006 Share Posted March 18, 2006 Hi,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):[code]<?phpfor($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]);/*** DISPLAYING IT HERE ***/echo '<table>';echo"<tr><td>{$count}</td><td>{$name[0]}</td><td>{$name[1]}</td><td>{$jersey}</td><td>{$position}</td><td>{$match[2]}</td></tr>";echo '</table>';}?>[/code]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 <br></span>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/5211-regex-preg_match-help/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.