Anita
Anita

Reputation: 1

Removing Images from RSS Feed Description when pulling feed to another site

I am almost completely on my own trying to solve this problem, know next to nothing about PHP and am in desperate need of help. A Wordpress news site redesign has images included in the description tag of the feed, we already had a way set up to pull those images so now the feed on other sites is seeing double. I want to turn off the image being pulled in the description tag and I'm having trouble figuring out how to accomplish that.

I have tried a few things, like strip_tag, shuffling code/HTML, etc., but I suspect most of my problem is not knowing where or how to implement them.

if ($rss = simplexml_load_file($feed)){  // (replace relative path with variable: $rssPath ).

$count = 0;
foreach($rss->channel->item as $item){
    if ($count < $items) {
         /*Set variables from RSS*/
          $title = $item->title;
          $desc = $item->description;
          $content = htmlspecialchars_decode($item->children('content', true)->encoded);
          preg_match('/(<img[^>]+>)/i', $content, 
$content_image);
//if(strstr($content, 'img')){
//            $content_trunc = 
substr($content,0,strpos($content,'</p>', 550)) . "...";
//}
//else {
//$content_trunc = substr($content,0,strpos($content,'</p>', 400)) . 
"...";
//}           
         $content_image = str_replace('class="', 
'class="media-object ', $content_image);
          $link = $item->link;  
          $pubdate = $item->pubDate; 
          $pubMonth = substr($pubdate, 8, 3);            
          $pubDay = substr($pubdate, 5, 2);

             /*Display items*/ 
            $output= "<div class='row'>\n<div class='col-md-3'>";                                   

            $output = $output . 
                "           <a href='". $link ."'>" 
                 . $content_image[0]  . 
                "               </div>
                <div class='col-md-9'><span class='news-headline' style='vertical-align:top;'>" . $title . "</span>
                            </a>" . "\n                          
                       <p class='news-blurb'>" . $desc . "</p>
                       </div>\n</div>\n <hr />";                    


            echo $output;
            $count++;             
    }
}

This is the description tag, in short:

<description><![CDATA[<img width="150" height="150" src="http://placehold.it/150.150" class="attachment-thumbnail size-thumbnail wp-post-image" alt="" />news article description here [...]]]></description>

Please help! This is a language I want to learn, but I'm a long way from it yet. All I know is that I need to filter content out of $desc. but I don't know how.

Upvotes: 0

Views: 1029

Answers (1)

Petr
Petr

Reputation: 460

Try preg_replace("/<img[^>]+\>/i", "", $desc); after $desc = $item->description; line.

Upvotes: 1

Related Questions