Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richellyitalo/2f522ffabaee42cc7e513df7f0b9336e to your computer and use it in GitHub Desktop.
Save richellyitalo/2f522ffabaee42cc7e513df7f0b9336e to your computer and use it in GitHub Desktop.
Using PHP's SimpleXML class to find the attributes of a <media:content> element in an MRSS file.
<?php
$mrss =<<<EOS
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/"
xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule">
<channel>
<title>My Movie Review Site</title>
<link>http://www.foo.com</link>
<description>I review movies.</description>
<item>
<title>Movie Title: Is this a good movie?</title>
<link>http://www.foo.com/item1.htm</link>
<media:content url="http://www.foo.com/trailer.mov" fileSize="12216320" type="video/quicktime" expression="sample" />
<creativeCommons:license>
http://www.creativecommons.org/licenses/by-nc/1.0
</creativeCommons:license>
<media:rating>nonadult</media:rating>
</item>
</channel>
</rss>
EOS;
$xml = new SimpleXMLElement($mrss);
$content = $xml->channel->item->children('media', true)->content;
$contentattr = $content->attributes();
foreach($contentattr as $name => $value){
echo $name . ' = '. $value . '<br />';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment