strip_tags() function is used to remove HTML and PHP tags from a string.
HTML comments and PHP tags are also removed.
It returns the stripped string.
<?php
$My_string = ’<p>This is example of paragraph</p>,
<div>This is an exmple of division,</div>
<p>This is another example of paragraph</p>,
<span>This is an example of span tag.</span>’;
$stripped_string = strip_tags($My_string);
echo $stripped_string;
?>
Output :
This is example of paragraph, This is an exmple of division, This is another example of paragraph, This is an example of span tag.
<?php
$My_string = ’<p>This is example of paragraph</p>,
<div>This is an exmple of division,</div>
<p>This is another example of paragraph</p>,
<span>This is an example of span tag.</span>’;
$stripped_string = strip_tags($My_string,’<div>’);
echo $stripped_string;
?>
Output :-
This is example of paragraph,
This is another example of paragraph, This is an example of span tag.
In above example,<div> is allowable tag, so it will return string with the <div> tag used.
Filed under: php, String Functions, strip_tags()
