tags:

views:

71

answers:

1

I want to access the 'url' attribute in the media:content element below. I am pretty sure this gives me the media:content, but I can not seem to get the url (see what I tried below):

$theContent = $item->children('media', true)->content;

xml:

<item>
<media:content type="image/jpeg" url="my url" />
</item>

I have tried variations:

 $theURL = $item->children('media', true)->content['url'];

and

$mediaItem=$item->children('media', true)->content;
$contentItem=$mediaItem->children('content', true);
$url = $contentItem['url'];

No luck. ??

A: 

Complete working code with output:

<?php
$xml = '<item>
<media:content type="image/jpeg" url="my url" />
</item>';

$theContent = @new SimpleXMLElement($xml);

$attributes = $theContent->content->attributes();
echo $attributes['url'];  //outputs: my url
?>

References: SimpleXML Attributes

shamittomar
thank you, missed that ->attributes() !
Scott
You're welcome.
shamittomar