Core Function StripTags

From Sputnik Wiki
Jump to: navigation, search
StripTags( <str>, <allowable_tags> )

Contents

Description

Strip HTML tags from a string.

Parameters

str

The input string.

allowable_tags

Optional; You can use the optional second parameter to specify tags which should not be stripped.

Note:
HTML comments and PHP style tags are also stripped. This is hardcoded and can not be changed with allowable_tags. 
Note:
This parameter should not contain whitespace. StripTags() sees a tag as a case-insensitive string between < and the first whitespace or >.
It means that StripTags("<br/>", "<br>") returns an empty string. 
Note:
You can use an array here for example array("<p>", "<a>");

Return Value

Returns the stripped string.

Remarks

None.

Example

my $text = '<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>';
echo StripTags($text);
echo "\n";
 
// Allow <p> and <a>
echo StripTags($text, '<p><a>');
echo "\n";
 
// Same as above but this time use an array
my $arr = array('<p>', '<a>');
echo StripTags($text, $arr);
echo "\n";
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox