PHP Get Largest Image for an Artist

I have the following code

    $xml = simplexml_load_file("");
    $artistTag= $xml->artist->children();
    $largeImage = $artistTag[7];
    echo '<img src="'.$largeImage.'" />';     

This will target the 7th node – however the 7th node might not exist so this won’t work. Is there anyway to specifically target the large, extralarge or mega nodes?

Example XML

<lfm status="ok">
<image size="small">

<image size="medium">

<image size="large">

<image size="extralarge">

<image size="mega">

<image size="">


So if mega doesn’t exist, go for extralarge, if that doesn’t exist, go to large etc


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s