PHPstrip_tags: the strip_tags label. PHPstrip_tags: how to retain multiple HTML tags. This document describes how to retain multiple HTML tags by using the PHPstrip_tags function, you can use the second parameter to set the method for retaining multiple HTML tags without deleting PHP strip_tags. the strip_tags tag
This article describes how to retain multiple HTML tags by using the PHP strip_tags function. you can use the second parameter to set tags that do not need to be deleted, mainly involving the second parameter of strip_tags.
Strip_tags function
Syntax
String strip_tags (string str [, string allowable_tags])
Returns a string that removes HTML tags. you can use the second parameter to set tags that do not need to be deleted.
Usage:
Premise: if there is such a string,
The code is as follows:
$ Str ="
I'm fromHelping customers
";
1. do not retain any HTML tags. the code will be like this:
The code is as follows:
Echo strip_tags ($ str );
// Output: I am from the customer center
2. if only one tag is retained, you only need to write the string to the second parameter of strip_tags:
The code is as follows:
Echo strip_tags ($ str ,"");
// Output: I am from the customer center
3. retain
And... Multiple tags, separated by spaces, must be written to the second parameter of strip_tags:
The code is as follows:
Echo strip_tags ($ str ,"
");
// Output:
I'm fromHelping customers
What if you want to use php to delete a specific tag in the html tag?
This requires code implementation, as shown below:
function strip_selected_tags($text, $tags = array()) { $args = func_get_args(); $text = array_shift($args); $tags = func_num_args() > 2 ? array_diff($args, array($text)) : (array) $tags; foreach($tags as $tag) { if (preg_match_all('/<'.$tag. '[^>]*>([^<]*)
/iu', $text, $found)) { $text = str_replace($found[0], $found[1], $text); } } return preg_replace('/(<('.join('|', $tags). ')( | |.)*/>)/iu', '', $text);}$str = "[url="] 123[/url]"; echo strip_selected_tags($str, array('b'));
Http://www.bkjia.com/PHPjc/1133109.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1133109.htmlTechArticlePHP strip_tags to retain multiple HTML tags, strip_tags label this article introduces the PHP strip_tags function to retain multiple HTML tags, you can use the second parameter to set do not need to delete...