Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does PHP strip_tags retain multiple HTML tags

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report