Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How does PHP strip_tags retain multiple HTML tags

Shulou Source: shulou.com Published: 2022-05-31 13:14:35 09月23日 Update

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 ('/] * >) ([^)

Tags: Tags codes multiple parameters characters strings articles output content appropriateness usage functions premises ideas new knowledge methods more tags steps knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Information Redmi Apple Huawei