Mark Bogner
Mark Bogner

Reputation: 471

PHP XML RSS Assistance

I'm reading a podcast RSS feed from wordpress (one of my shows) - and it works great - but, In the RSS feed's XML there's a bunch of other stuff that I don't want in the "description" like this stuff (this is exactly how it looks in the feed - it's divs and javascript for facebook and twitter things that aren't necessary for what I'm doing):

<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

How can I tell it NOT to pull this information in the description?

This is my general code that I found online:

<?php
    $rss = new DOMDocument();
    $rss->load('http://mywordpresssite.com/rss/feed/');
    $feed = array();
    foreach ($rss->getElementsByTagName('item') as $node) {
        $item = array ( 
            'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
            'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
            'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
            'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
            );
        array_push($feed, $item);
    }
    $limit = 5;
    for($x=0;$x<$limit;$x++) {
        $title = str_replace(' & ', ' &amp; ', $feed[$x]['title']);
        $link = $feed[$x]['link'];
        $description = $feed[$x]['desc'];
        $date = date('l F d, Y', strtotime($feed[$x]['date']));
        echo '<p><strong><a href="'.$link.'" title="'.$title.'">'.$title.'</a></strong><br />';
        echo '<small><em>Posted on '.$date.'</em></small></p>';
        echo '<p>'.$description.'</p>';
    }
?>

Like I said, the code works - but I really need to get rid of all that excess text and junk that follows in the description.

Any thoughts would be helpful.

Upvotes: 0

Views: 61

Answers (1)

Mark Bogner
Mark Bogner

Reputation: 471

Ok, never mind - I figured it out.

I used this:

$text =  substr($description, 0, strpos( $description, '&lt;'));

And it will take everything after the &alt; and get rid of it.

Upvotes: 1

Related Questions