Member Avatar for doctorphp

Hey everyone,

Parsing RSS is not my strong point and I am making a news feed for a client and they want me to use the Yahoo News RSS feed. I am using the following code.

$url = "";          
$xml = simplexml_load_file( $url );
<h3 id="ln">Latest News</h3>

$newsCount = 0;
foreach ( $xml->channel->item as $item ) {

    <h4><?php echo $item->title; ?></h4>
    <br />

    if( ++$newsCount == 3 ) {



I need to get this part of the feed.

<media:content url="" type="image/jpeg" width="130" height="86"/>

How do I incorporate this into the above code?

Thanks in advance.

Since the media is part of a namespace you have to access that namespace to be able to access those nodes easily.

There are a few different ways for it to be achieved but I think this is the cleanest overall.


$feed = file_get_contents("");
$xml = new SimpleXmlElement($feed);

foreach ($xml->channel->item as $entry){
  $namespaces = $entry->getNameSpaces(true);
  $media = $entry->children($namespaces['media']); 
  echo $media->text;
  echo $media->credit;

Untested but you should get the general idea.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.