WEB PHP and XML parsing help!

Discussion in 'OT Technology' started by littleman, Aug 11, 2008.

  1. littleman

    littleman I took an AMEX survey and all I got was this crapp

    Joined:
    Sep 9, 2004
    Messages:
    2,597
    Likes Received:
    0
    Location:
    NY
    Hi all!

    I'm doing some parsing of an XML returned by last.fm but im having a problem getting the the middle IMAGE tag (size = "medium") parsed. The code below only returns the small one... the size="medium" is throwing me the curve ball.

    Any help is much appreciated! :wiggle:

    @ $fmxml = simplexml_load_file( 'grabAlbum.xml' );
    @ $fmurl = $fmxml->album[0]->url;
    $fmimg = $fmxml->album[0]->image;
    echo "$fmurl";
    echo "$fmimg";

    Code:
    <lfm status="ok">
    −
    <album>
    <name>Love Is Noise</name>
    <artist>The Verve</artist>
    <id>3821613</id>
    <mbid/>
    <url>http://www.last.fm/music/The+Verve/Love+Is+Noise</url>
    <releasedate>    22 Jul 2008, 00:00</releasedate>
    <image size="small">http://userserve-ak.last.fm/serve/34/7037583.jpg</image>
    <image size="medium">http://userserve-ak.last.fm/serve/64/7037583.jpg</image>
    <image size="large">http://userserve-ak.last.fm/serve/126/7037583.jpg</image>
    <listeners>3426</listeners>
    <playcount>15558</playcount>
    <toptags>
          </toptags>
    </album>
    </lfm>
     
  2. jdw

    jdw New Member

    Joined:
    Dec 31, 2005
    Messages:
    4,429
    Likes Received:
    0
    Location:
    ND
    will ->image be returning an array? Have you tried ->image[1]?
     
  3. littleman

    littleman I took an AMEX survey and all I got was this crapp

    Joined:
    Sep 9, 2004
    Messages:
    2,597
    Likes Received:
    0
    Location:
    NY
    That works! Is there anyway to make it foolproof to grab the medium? Incase its not always the 2nd one in the array?
     

Share This Page