PHP Snippets
Name:Strip HTML Tags
Description: Strip all HTML tags from a string of text. This would be useful for user submitted form.
Code below...
>
<?php
//Text with a header tag
$html = "<h1>Strip this!</h1>";
//Strip all tags from the above variable using PHP's strip_tags() function
$html = strip_tags($html);
//Display the result
echo $html;
//That would display: Strip this! (Without the header tag)
//From PHP.net
//Because strip_tags() does not actually validate the HTML, partial,
//or broken tags can result in the removal of more text/data than expected.
?>
//Text with a header tag
$html = "<h1>Strip this!</h1>";
//Strip all tags from the above variable using PHP's strip_tags() function
$html = strip_tags($html);
//Display the result
echo $html;
//That would display: Strip this! (Without the header tag)
//From PHP.net
//Because strip_tags() does not actually validate the HTML, partial,
//or broken tags can result in the removal of more text/data than expected.
?>