I'm using simplepie to pull full Wordpress blog entries into my HTML/CSS site. Some of these blog entries contain links or formatting tags, etc., in the body/description, but no matter how I try, the descriptions come in as plain text, with this html stripped from the code. For obvious reasons, the links are particularly important. (You'll notice some dreaded "click here" verbiage in some of the entries - still working on getting my client away from that kinda dirty talk, but the links are crucial nonetheless).

I've been searching high and low for the answer to this one, seen others that have had the problem but have yet to see a solution. I thought my desired behavior was the default if you just followed Simplepie's baseline example, but I guess I was wrong. :\ However, if you just enter my feed URL into simplepie.org's demo generator, the links show up. Too bad I can't look at thatcode.

I'd sure appreciate some help with this one. Thanks all!

include_once $_SERVER['DOCUMENT_ROOT'] . '/inc/simplepie.inc'; 

$feednews = new SimplePie();


?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>


    <div class="header">
        <h1><a href="<?php echo $feednews->get_permalink(); ?>"><?php echo $feednews->get_title(); ?></a></h1>
        <p><?php echo $feednews->get_description(); ?></p>

    Here, we'll loop through all of the items in the feed, and $item represents the current item in the loop.
    foreach ($feednews->get_items() as $item):

        <div class="item">
            <h2><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h2>
            <p><?php echo $item->get_description(); ?></p>
            <p><small>Posted on <?php echo $item->get_date('j F Y | g:i a'); ?></small></p>

    <?php endforeach; ?>


3 answers


The method you called $feednews->strip_htmltags(false) should really have done the trick. Assuming that SimplePie is working correctly, then you have to wonder why the links are being stripped out. It might be that they are stripped before they are sent to you. There should be a way to check this. Look at the raw feed you are asking for and check for <a> tags. Or you might try and strip out a different element only, like $feednews->strip_htmltags(array('h1')) The point is that you want to make sure that the feed you are pulling in is what you expect it to be before you start parsing it with SimplePie.

Also, you might want to take a look at what SimplePie has setup to remove by default. http://simplepie.org/wiki/reference/simplepie/strip_htmltags

Answered about 8 years ago by Abinadi Ayerdis
  • Thanks Abinadi - Yeah, that's the rub. This is pretty much the default code from simplepie, (I just added the strip_htmltags) and the raw feed (included in the above code example) works like a charm - all the HTML is working. Like I said, if I enter the raw feed into their demo generator at http://simplepie.org/demo/ it generates the HTML with all the links. That's why I'm so flummoxed here. matt kristiansen about 8 years ago

I know this is over a year old, but in case anyone else is in need of the answer just replace $item->get_description(); with $item->get_content();

Answered over 6 years ago by George Sheehy

Still haven't found a solution to this, sadly. I have no clue as to why these tags would be stripped out, whether I include the strip_htmltags method or not. Anyone?

Answered about 8 years ago by matt kristiansen
  • What if you set the cache *after* you set the strip_htmltags to none? Tony Crockford about 8 years ago