How does PHP strip_tags retain multiple HTML tags
In this article Xiaobian for you to introduce in detail "PHP strip_tags how to retain multiple HTML tags", the content is detailed, the steps are clear, the details are handled properly, I hope this "PHP strip_tags how to retain multiple HTML tags" article can help you solve your doubts, the following follows the editor's ideas slowly in depth, together to learn new knowledge.
Strip_tags function
Grammar
String strip_tags (string str [, string allowable_tags])
Returns a string with the HTML tag removed; you can use the second parameter to set the tag that does not need to be deleted.
How to use it:
Premise: if there is such a string now
The copy code is as follows:
$str = "
I come from
"
1, do not retain any HTML tags, the code would look like this:
The copy code is as follows:
Echo strip_tags ($str)
/ / output: I am from
2. If you keep only one tag, you only need to write the string to the second parameter of strip_tags:
The copy code is as follows:
Echo strip_tags ($str, "")
/ / output: I am from
3, to keep
With. Multiple tags. You only need to separate multiple tags with spaces and write them to the second parameter of strip_tags:
The copy code is as follows:
Echo strip_tags ($str, "
")
/ / output:
I come from
What if you want to use php to delete a specific tag in a html tag?
This requires code to implement, as follows:
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 ('/] * >) ([^)