SimplePie 1.5 is now available!

SimplePie Documentation.  Learn how to use this thing.  It's way better than going to school.

You are here: Documentation » API Reference » SimplePie » strip_htmltags()

strip_htmltags()

Description

class SimplePie {
	strip_htmltags ( [$tags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style')] )
}

Set which HTML tags get stripped from an entry's content.

The default set of tags is stored in the property SimplePie→strip_htmltags, not to be confused with the method SimplePie→strip_htmltags(). This way, you can modify the existing list without having to create a whole new one.

Availability

  • Available since SimplePie Beta 2.

Parameters

tags

An array of the HTML tags you want to strip.

Examples

Don't strip any tags (not recommended)

This code will prevent ANY HTML tags from being stripped from the feed content. This is potentially unsafe, so we do not recommend it.

$feed = new SimplePie();
$feed->set_feed_url('http://simplepie.org/blog/feed/');
$feed->strip_htmltags(false);
$feed->init();
$feed->handle_content_type();
echo $feed->get_title();

Strip only blink, font, and marquee

This will ONLY strip out blink, font, and marquee tags, and will allow all other tags to be displayed.

$feed = new SimplePie();
$feed->set_feed_url('http://simplepie.org/blog/feed/');
$feed->strip_htmltags(array('blink', 'font', 'marquee'));
$feed->init();
$feed->handle_content_type();
echo $feed->get_title();

Add h1, a, and img to the default list

This will take the existing list of tags to strip out by default (stored in the $feed→strip_htmltags variable), and add h1, a, and img to that list so that these tags are also stripped out by default.

$feed = new SimplePie();
$feed->set_feed_url('http://simplepie.org/blog/feed/');
$feed->strip_htmltags(array_merge($feed->strip_htmltags, array('h1', 'a', 'img')));
$feed->init();
$feed->handle_content_type();
echo $feed->get_title();

Remove object, param, and embed from the default list

This will take the existing list of tags to strip out by default (stored in the $feed→strip_htmltags variable), and remove object, param, and embed from that list so that these tags are NOT stripped out by default.

$feed = new SimplePie();
$feed->set_feed_url('http://simplepie.org/blog/feed/');
 
// Remove these tags from the list
$strip_htmltags = $feed->strip_htmltags;
array_splice($strip_htmltags, array_search('object', $strip_htmltags), 1);
array_splice($strip_htmltags, array_search('param', $strip_htmltags), 1);
array_splice($strip_htmltags, array_search('embed', $strip_htmltags), 1);
 
$feed->strip_htmltags($strip_htmltags);
 
$feed->init();
$feed->handle_content_type();
echo $feed->get_title();

See Also


reference/simplepie/strip_htmltags.txt · Last modified: 2011/03/06 03:56 (external edit)