Example of strip_tags () function in php

Source: Internet
Author: User
Example of strip_tags () function in php
This article describes how to use strip_tags () function in php. if you need it, refer.

In php, the strip_tags () function can remove HTML, XML, and PHP labels.

Usage: The allow following strip_tags (string, allow) is optional. If entered, the tag is allowed.

Appendix. php uses strip_tags to clear all tags.

String strip_tags (string str );

The strip_tags function removes any HTML and PHP tag strings contained in the string. If the HTML and PHP tags of a string are incorrect, for example, if a greater symbol is missing, an error is returned.

String strip_tags (string str [, string allowable_tags]) returns a string to remove html tags. you can use the second parameter to set tags that do not need to be deleted.

For example:

     

Question 1: How does strip_tags retain multiple HTML tags?

You only need to separate multiple tags with spaces and write them to the second parameter of strip_tags. the code is as follows:

strip_tags($str, "

");

Question 2: How does php delete a specific tag in the html tag?

Code:

     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');?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.