Archive

Archive for December, 2009

PHP strip_tags : Remove HTML markup from a string

December 10th, 2009 Shyju No comments

strip_tags is a PHP function which will remove all HTML mark up from a string.This will remove PHP tags and XML mark from the input string if there is any

Ex : $strPreviewName=’I am <b>Bold</b>and<i>Italic</i>’;

The output of echo $strPreviewName would show

I am Bold and Italic.

Now this would make problems in cases where u need to take a substring of the first string or trim the string to  take the first 50 characters .Then it would break the HTML markup and which will leads to the rest of the page contents to be affected by the styles mentioned in the first string. In this case,we can use strip_tags function to remove all HTML markups from the string.

Ex : $strPreviewName=’I am <b>Bold</b>and<i>Italic again</i>’;

$strPreviewNameUpdated =strip_tags($strPreviewName);

The output of echo $strPreviewNameUpdatedwould show

I am Bold and Italic.

Categories: PHP Tags: