-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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