PHP strip_tags

 The PHP strip_tags function can remove the HTML or PHP tags contained in the string , or you can set the reserved tags that will not be removed according to the needs of the time, so that the output result is more flexible. The strip_tags function is used to remove tags, and its effect is not the same as that used by htmlspecialchars to convert tags. PHP strip_tags basic syntax


String strip_tags( $string , $allowable_tags )


The first parameter $string in the parentheses of the strip_tags function is a required item, that is, the string to be processed, and the second parameter $allowable_tags is an optional item and does not have to be filled in. Its function is to set which tags To keep, tags with settings will be reserved by the strip_tags function, but the annotations will definitely be deleted.

PHP strip_tags example reference
<?php
$string_1 = '<p>Welcome to  Jason SEO.</p><a href="#">Test link.</a><!-- 這裡是註解 --> ';
echo strip_tags($string_1).'<br>';
$string_2 = '<p>Welcome to  Jason SEO.</p><a href="#">Test link.</a><!-- 這裡是註解 --> ';
echo strip_tags($string_2,'<p><a>');
?>
The above output result is as
Welcome to  Jason SEO.Test link.

Welcome to Jason SEO.

Test link.

The <br> tag in the original file of the webpage, on the left is the output result of strip_tags($string_1), no reserved tags are set, so in principle, all HTML tags are eliminated, and the right of the <br> tag is the output reserved<p> The result of the complete function of the <a> tag, so it shows the effect of paragraphs and hyperlinks .

Post a Comment

0 Comments