If you ever need to strip out the HTML or PHP tags from data, PHP gives you a way to do this via the strip_tags() function, which was introduced to us in PHP version 3.0.8. In PHP 5.0.0 and up the strip_tags() function is now binary safe.
The strip_tags() function strips a string from HTML and PHP tags and even XML tags. The strip_tags() function has two parameters, which are listed below:
- string
-
The first parameter is the input string which is a required string that you want stripped of HTML and PHP tags.
Here is how to code the required string parameter for the strip_tags() function.
<?php $required_string = '<p>Data and text to be <strong>stripped.</strong></p>'; echo strip_tags($required_string); ?>
- allowable_tags
-
The second parameter specifies the allowable tags that should not be stripped. In PHP version 4.3.0 and up HTML comments are always stripped. You should also know that when the HTML comments and PHP tags are stripped they cannot be changed with the allowable_tags parameter because its hard coded into the strip_tags() function.
Here is how to code the second parameter allowable_tags for the strip_tags() function.
<?php $required_string = '<p>Data and text to be <strong>stripped.</strong></p>'; echo strip_tags($required_string, '<p><strong>'); ?>
Here is how to code the strip_tags() function and its required string parameter.
<?php $required_string = '<p>Data and text to be <strong>stripped.</strong></p>'; echo strip_tags($required_string); ?>
If you need more information about the strip_tags() function check out the PHP manual at http://www.php.net/manual/en/function.strip-tags.php