SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2007
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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!

    Code:
    <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"/>
    −
    <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>
    iPadFlava.com - The best free iPad Wallpapers and Backgrounds!

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    PHP Code:
    $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"/>

    <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


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •