HOW TO USE THE strip_tags() FUNCTION IN PHP
The strip_tags() function strips html tags from a string. It takes two parameters: the string to perform the action on and the specified html tags NOT to strip out. This is a useful function to prevent users from entering malicious
scripts or unauthorized html onto your forms.
If the html tags to keep parameter is not specified, then strip_tags() strips all html tags by default.
Example:
$string="<b><i>John James was here</i></b>";
$newstring=strip_tags($string);
echo $newstring;
The above will output: John James was here
This output is neither bold nor in italics as all html tags were stripped out.
You can also specify what html tags to keep.
Example:
$string="<b><i>John James was here</i></b>";
$newstring=strip_tags($string, "<b>");
echo $newstring;
The above will output: John James was here
Note that the above is output in bold only as we told the function to keep the bold tags. The italic was stripped out.
|