The function strip_tags() does completely get rid of all HTML elements. If you just want to keep some elements (for example, some limited formatting functionalities with <b> and <i> and <br /> tags), you provide a list of allowed values in the second parameter for strip_tags().
Syntax
strip_tags(string,allow)
Here, the first parameter string specifies the string to check and the second parameter allowspecifies allowable tags. These tags will not be removed. The given example demonstrates how to remove all HTML tags except paragraph and italics tags -
<?php
$input = 'The term <i>Official Ireland</i> is commonly <br />' .
'used in <b>the Republic of Ireland</b> to denote<br />' .
' the media, cultural and religious establishment. '.
'<script>alert("Nice try!");</script>' .
'<img src="/spam.jpg" />';
echo strip_tags($input, '<b><br><i>');
?>
Output of the above code
The term Official Irelandis commonly
used inthe Republic of Ireland to denote
the media, cultural and religious establishment. alert("Nice try!");
Solution
The function strip_tags() does completely get rid of all HTML elements. If you just want to keep some elements (for example, some limited formatting functionalities with <b> and <i> and <br /> tags), you provide a list of allowed values in the second parameter for strip_tags().
Syntax
strip_tags(string,allow)
Here, the first parameter string specifies the string to check and the second parameter allowspecifies allowable tags. These tags will not be removed. The given example demonstrates how to remove all HTML tags except paragraph and italics tags -
Output of the above code
need an explanation for this answer? contact us directly to get an explanation for this answerThe term Official Ireland is commonly used in the Republic of Ireland to denote the media, cultural and religious establishment. alert("Nice try!");