Help extracting data

I’m trying to extract the data and place them into variables from the below xml document from the line that says :<day0 name=“Monday” date=“01/25” max=“50” min=“41” code=“13” phrase=“Showers”/>

basically I would like it to be like $name=Monday, $max=50 etc…

I’m not sure if this would be a job for preg_match or something else and if so, what would be the best way to do this?

Thanks for any help!


<data>
<provider>qwikcast.com</provider>
<date>01/25/2010</date>
<time>11:05</time>
<loc city="Longview" state="WA" country="US" county="Cowlitz" lat="46.1300" lon="-122.9300" elev="21"/>
<icon dir="NA"/>
&#8722;
<fcst>
<day0 name="Monday" date="01/25" max="50" min="41" code="13" phrase="Showers"/>
<day1 name="Tuesday" date="01/26" max="49" min="37" code="12" phrase="PM Showers"/>
<day2 name="Wednesday" date="01/27" max="49" min="35" code="2" phrase="Partly Cloudy"/>
<day3 name="Thursday" date="01/28" max="51" min="36" code="16" phrase="Light Rain"/>
<day4 name="Friday" date="01/29" max="50" min="42" code="16" phrase="Light Rain"/>
</fcst>
<obs id="KKLS" time="10:35 AM" code="1" phrase="Clear" tempUnit="F" temp="46" appTemp="46" appWord="Apparent" dew="42" rh="87" windSpd="11" windDir="SSE" windUnit="mph" vis="10" visUnit="mi" baro="29.91" baroUnit="in"/>
</data>

$xmlstr = '<data>
<provider>qwikcast.com</provider>
<date>01/25/2010</date>
<time>11:05</time>
<loc city="Longview" state="WA" country="US" county="Cowlitz" lat="46.1300" lon="-122.9300" elev="21"/>
<icon dir="NA"/>
&#8722;
<fcst>
<day0 name="Monday" date="01/25" max="50" min="41" code="13" phrase="Showers"/>
<day1 name="Tuesday" date="01/26" max="49" min="37" code="12" phrase="PM Showers"/>
<day2 name="Wednesday" date="01/27" max="49" min="35" code="2" phrase="Partly Cloudy"/>
<day3 name="Thursday" date="01/28" max="51" min="36" code="16" phrase="Light Rain"/>
<day4 name="Friday" date="01/29" max="50" min="42" code="16" phrase="Light Rain"/>
</fcst>
<obs id="KKLS" time="10:35 AM" code="1" phrase="Clear" tempUnit="F" temp="46" appTemp="46" appWord="Apparent" dew="42" rh="87" windSpd="11" windDir="SSE" windUnit="mph" vis="10" visUnit="mi" baro="29.91" baroUnit="in"/>
</data>' ;

$xml = new SimpleXMLElement($xmlstr);

 foreach( $xml->fcst as $days ) 
   foreach( $days as $day )
     echo $day['name'] ;


gives: MondayTuesdayWednesdayThursdayFriday