PHP strip_tags methods for keeping multiple HTML tags, strip_tags tags
This article describes the PHP strip_tags function to preserve multiple HTML tags, you can use the second parameter to set a label that does not need to be deleted, mainly related to the second parameter of Strip_tags
Strip_tags function
Grammar
String Strip_tags (String str [, String allowable_tags])
Returns a string that removes the HTML tag; You can use the second parameter to set a label that does not need to be deleted.
How to use:
Premise: If there is such a string now,
Copy the Code code as follows:
$str = "
I'm from the Help house .
";
1, do not keep any HTML tags, the code will be like this:
Copy the Code code as follows:
echo Strip_tags ($STR);
Output: I'm from the Help house.
2, to keep only one label, just write the string to the second parameter of Strip_tags:
Copy the Code code as follows:
Echo strip_tags ($str, "");
Output: I'm from the Help house.
3, to keep
With the. Multiple labels, you only need to separate multiple labels with a space and write to the second parameter of Strip_tags:
Copy the Code code as follows:
Echo strip_tags ($str, "
");
Output:
I'm from the Help house .
What if you want to use PHP to remove specific tags from HTML tags?
This requires code to be implemented, 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 ('/< '. $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.html www.bkjia.com true http://www.bkjia.com/PHPjc/1133109.html techarticle PHP Strip_tags The method of keeping multiple HTML tags, strip_tags tags This article describes the PHP strip_tags function to keep multiple HTML tags, you can use the second parameter to set no need to delete ...