cowboysdude Posted January 23, 2015 Share Posted January 23, 2015 I have gotten a lot of help with my php to get, read and parse and xml file for NFL scores... it was working really great but then I found something and now I have a new problem... Currently it reads as follows: $url="http://www.nfl.com/liveupdate/scorestrip/postseason/ss.xml "; $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); // get the url contents $data = curl_exec($ch); // execute curl request curl_close($ch); $xml = simplexml_load_string($data); $games = array( 'REG' => array(), 'WC' => array(), 'DIV' => array(), 'CON' => array(), 'SB' => array() ); foreach($xml->gms->g as $game) { // it's a single game // if (!empty($game['vtn'])) { $games[(string) $game['gt']][] = $game; } } ?> <div class='ticker'> <ul> <?php foreach ($games as $gametype => $subgames) { foreach ($subgames as $game) { if ($game['gt'] == 'REG') { ?> <li data-subcategory='Regular Season' data-category='Week <?= $game['w'] ?>' data-color='1979ab'> <a href='#'><b><?= $game['h'] ?> <?= $game['hs'] ?> <?= $game['v'] ?> <?= $game['vs'] ?></b></a> </li> <?php } else if ($game['gt'] == 'WC') { ?> <li data-subcategory='Round 1' data-category='Wild Card Games' data-color='1979ab'> <a href='#'><b><?= $game['htn'] ?> <?= $game['hs'] ?> <?= $game['vtn'] ?> <?= $game['vs'] ?></b></a> </li> <?php } else if ($game['gt'] == 'DIV') { ?> <li data-subcategory='Round 2' data-category='Divisional Games' data-color='14ab05'> <a href='#'><b><?= $game['htn'] ?> <?= $game['hs'] ?> <?= $game['vtn'] ?> <?= $game['vs'] ?> <?= $game['d'] ?> at <?= $game['t'] ?></b></a> </li> <?php } else if ($game['gt'] == 'CON') { ?> <li data-subcategory='Championship Games' data-category='Conference Games' data-color='000000'> <a href='#'><b><?= $game['htn'] ?> <?= $game['hs'] ?> <?= $game['vtn'] ?> <?= $game['vs'] ?> <?= $game['d'] ?> at <?= $game['t'] ?></b></a> </li> <?php } else if ($game['gt'] == 'SB') { ?> <li data-subcategory='<img src=localhost/joomla/modules/mod_scores/images/nfl.png>' data-category='Super Bowl' data-color='000000'> <a href='#'><b><?= $game['htn'] ?> <?= $game['hs'] ?> <?= $game['vtn'] ?> <?= $game['vs'] ?> <?= $game['d'] ?> at <?= $game['t'] ?></b></a> </li> <?php } } } ?> </ul> </div> I did notice that this will work fantastic during the post season but in regular season it's a new issue... the post season xml reads out team names likes this "Carolina Panthers" as one of the elements.. however during the regular season that gets shortened to: "CAR". How do I get it to read the xml and change "CAR" Into "Caroline Panthers"? I have to do this for all 32 teams... Thanks everyone! Quote Link to comment Share on other sites More sharing options...
requinix Posted January 23, 2015 Share Posted January 23, 2015 Is there "CAR" anywhere in the element? If not then you'll have to provide that Carolina Panthers CAR mapping somewhere yourself. Quote Link to comment Share on other sites More sharing options...
scootstah Posted January 23, 2015 Share Posted January 23, 2015 There's a couple ways to solve this problem. To answer what you asked, you can convert the abbreviations into team names like this: $search = array( 'CAR', 'ARI', 'ATL', ); $replace = array( 'Carolina Panthers', 'Arizona Cardinals', 'Atlanta Falcons', ); $data = 'CAR'; $data = str_replace($search, $replace, $data); // $data = Carolina PanthersYou didn't provide a sample of what the XML looks like, so that may or may not work. If $data is just the abbreviation, like in this example, then it should work. But if it's a whole bunch of other text, then you may end up replacing parts of a word or something. Quote Link to comment Share on other sites More sharing options...
cowboysdude Posted January 23, 2015 Author Share Posted January 23, 2015 (edited) There's a couple ways to solve this problem. To answer what you asked, you can convert the abbreviations into team names like this: $search = array( 'CAR', 'ARI', 'ATL', ); $replace = array( 'Carolina Panthers', 'Arizona Cardinals', 'Atlanta Falcons', ); $data = 'CAR'; $data = str_replace($search, $replace, $data); // $data = Carolina PanthersYou didn't provide a sample of what the XML looks like, so that may or may not work. If $data is just the abbreviation, like in this example, then it should work. But if it's a whole bunch of other text, then you may end up replacing parts of a word or something. In play off time it looks like this: <ss> <gms w="21" y="2014" t="POST" gd="0" bf="0" bph="0"> <g eid="2015010301" gsis="56492" d="Sat" t="8:15" q="F" htn="Pittsburgh Steelers" hnn="steelers" h="PIT" hs="17" vtn="Baltimore Ravens" vnn="ravens" v="BAL" vs="30" n="NBC" rz="0" ga="" o="1" gt="WC"/> <g eid="2015010400" gsis="56493" d="Sun" t="1:05" q="F" htn="Indianapolis Colts" hnn="colts" h="IND" hs="26" vtn="Cincinnati Bengals" vnn="bengals" v="CIN" vs="10" n="CBS" rz="0" ga="" o="2" gt="WC"/> <g eid="2015011000" gsis="56495" d="Sat" t="4:35" q="F" htn="New England Patriots" hnn="patriots" h="NE" hs="35" vtn="Baltimore Ravens" vnn="ravens" v="BAL" vs="31" n="NBC" rz="0" ga="" o="3" gt="DIV"/> <g eid="2015011101" gsis="56498" d="Sun" t="4:40" q="F" htn="Denver Broncos" hnn="broncos" h="DEN" hs="13" vtn="Indianapolis Colts" vnn="colts" v="IND" vs="24" n="CBS" rz="0" ga="" o="4" gt="DIV"/> <g eid="2015011801" gsis="56500" d="Sun" t="6:50" q="F" htn="New England Patriots" hnn="patriots" h="NE" hs="45" vtn="Indianapolis Colts" vnn="colts" v="IND" vs="7" n="CBS" rz="0" ga="" o="5" gt="CON"/> <g eid="2015011800" gsis="56499" d="Sun" t="3:05" q="FO" htn="Seattle Seahawks" hnn="seahawks" h="SEA" hs="28" vtn="Green Bay Packers" vnn="packers" v="GB" vs="22" n="FOX" rz="0" ga="" o="6" gt="CON"/> <g eid="2015011100" gsis="56497" d="Sun" t="1:05" q="F" htn="Green Bay Packers" hnn="packers" h="GB" hs="26" vtn="Dallas Cowboys" vnn="cowboys" v="DAL" vs="21" n="FOX" rz="0" ga="" o="7" gt="DIV"/> <g eid="2015011001" gsis="56496" d="Sat" t="8:15" q="F" htn="Seattle Seahawks" hnn="seahawks" h="SEA" hs="31" vtn="Carolina Panthers" vnn="panthers" v="CAR" vs="17" n="FOX" rz="0" ga="" o="8" gt="DIV"/> <g eid="2015010401" gsis="56494" d="Sun" t="4:40" q="F" htn="Dallas Cowboys" hnn="cowboys" h="DAL" hs="24" vtn="Detroit Lions" vnn="lions" v="DET" vs="20" n="FOX" rz="0" ga="" o="9" gt="WC"/> <g eid="2015010300" gsis="56491" d="Sat" t="4:35" q="F" htn="Carolina Panthers" hnn="panthers" h="CAR" hs="27" vtn="Arizona Cardinals" vnn="cardinals" v="ARI" vs="16" n="ESPN" rz="0" ga="" o="10" gt="WC"/> <g eid="2015012500" gsis="56501" d="Sun" t="8:00" q="P" htn="Team Cris Carter" hnn="team carter" h="CRT" hs="0" vtn="Team Michael Irvin" vnn="team irvin" v="IRV" vs="0" n="ESPN" rz="0" ga="" o="11" gt="PRO"/> <g eid="2015020100" gsis="0" d="Feb 1" t="6:30" q="P" htn="Seattle Seahawks" hnn="seahawks" h="SEA" hs="0" vtn="New England Patriots" vnn="patriots" v="NE" vs="0" n="NBC" rz="0" ga="" o="12" gt="SB"/> </gms> During the regular season it looks like this: <ss> <gms w="17" y="2014" t="R" gd="1" bph="125"> <g eid="2014122801" gsis="56411" d="Sun" t="1:00" q="F" h="BAL" hnn="ravens" hs="20" v="CLE" vnn="browns" vs="10" rz="0" ga="" gt="REG"/> <g eid="2014122803" gsis="56413" d="Sun" t="1:00" q="F" h="HOU" hnn="texans" hs="23" v="JAC" vnn="jaguars" vs="17" rz="0" ga="" gt="REG"/> <g eid="2014122804" gsis="56414" d="Sun" t="1:00" q="F" h="KC" hnn="chiefs" hs="19" v="SD" vnn="chargers" vs="7" rz="0" ga="" gt="REG"/> <g eid="2014122805" gsis="56415" d="Sun" t="1:00" q="F" h="MIA" hnn="dolphins" hs="24" v="NYJ" vnn="jets" vs="37" rz="0" ga="" gt="REG"/> <g eid="2014122806" gsis="56416" d="Sun" t="1:00" q="F" h="MIN" hnn="vikings" hs="13" v="CHI" vnn="bears" vs="9" rz="0" ga="" gt="REG"/> <g eid="2014122807" gsis="56417" d="Sun" t="1:00" q="F" h="NE" hnn="patriots" hs="9" v="BUF" vnn="bills" vs="17" rz="0" ga="" gt="REG"/> <g eid="2014122808" gsis="56418" d="Sun" t="1:00" q="F" h="NYG" hnn="giants" hs="26" v="PHI" vnn="eagles" vs="34" rz="0" ga="" gt="REG"/> <g eid="2014122810" gsis="56420" d="Sun" t="1:00" q="F" h="TB" hnn="buccaneers" hs="20" v="NO" vnn="saints" vs="23" rz="0" ga="" gt="REG"/> <g eid="2014122811" gsis="56421" d="Sun" t="1:00" q="F" h="TEN" hnn="titans" hs="10" v="IND" vnn="colts" vs="27" rz="0" ga="" gt="REG"/> <g eid="2014122812" gsis="56422" d="Sun" t="1:00" q="F" h="WAS" hnn="redskins" hs="17" v="DAL" vnn="cowboys" vs="44" rz="0" ga="" gt="REG"/> <g eid="2014122800" gsis="56410" d="Sun" t="4:25" q="F" h="ATL" hnn="falcons" hs="3" v="CAR" vnn="panthers" vs="34" rz="0" ga="" gt="REG"/> <g eid="2014122813" gsis="56423" d="Sun" t="4:25" q="F" h="DEN" hnn="broncos" hs="47" v="OAK" vnn="raiders" vs="14" rz="0" ga="" gt="REG"/> <g eid="2014122802" gsis="56412" d="Sun" t="4:25" q="F" h="GB" hnn="packers" hs="30" v="DET" vnn="lions" vs="20" rz="0" ga="" gt="REG"/> <g eid="2014122815" gsis="56425" d="Sun" t="4:25" q="F" h="SEA" hnn="seahawks" hs="20" v="STL" vnn="rams" vs="6" rz="0" ga="" gt="REG"/> <g eid="2014122814" gsis="56424" d="Sun" t="4:25" q="F" h="SF" hnn="49ers" hs="20" v="ARI" vnn="cardinals" vs="17" rz="0" ga="" gt="REG"/> <g eid="2014122809" gsis="56419" d="Sun" t="8:30" q="F" h="PIT" hnn="steelers" hs="27" v="CIN" vnn="bengals" vs="17" rz="0" ga="" gt="REG"/> </gms> They don't spell out the Carolina they just use CAR and I want to use Carolina or I could also just use the panthers but having it with a capital P would work. Edited January 23, 2015 by cowboysdude Quote Link to comment Share on other sites More sharing options...
scootstah Posted January 23, 2015 Share Posted January 23, 2015 So, the "v" attribute is present in both places with the team abbreviation. So you could do something like this: $teams = array( 'CAR' => 'Carolina Panthers', 'ARI' => 'Arizona Cardinals', 'ATL' => 'Atlanta Falcons', ); echo $teams[$game['v']];If $game['v'] is CAR, then you'll get Carolina Panthers. Quote Link to comment Share on other sites More sharing options...
cowboysdude Posted January 23, 2015 Author Share Posted January 23, 2015 So, the "v" attribute is present in both places with the team abbreviation. So you could do something like this: $teams = array( 'CAR' => 'Carolina Panthers', 'ARI' => 'Arizona Cardinals', 'ATL' => 'Atlanta Falcons', ); echo $teams[$game['v']];If $game['v'] is CAR, then you'll get Carolina Panthers. OH awesome still being new at this I tend to make it harder then it has to be...LOL I think we all do that... Quote Link to comment 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.