Skip to content

Instantly share code, notes, and snippets.

@enderandpeter
Last active June 17, 2020 19:01
Show Gist options
  • Save enderandpeter/6b760140bf9d2ed9620c to your computer and use it in GitHub Desktop.
Save enderandpeter/6b760140bf9d2ed9620c 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