Tips for removing HTML tags from strings using php

Source: Internet
Author: User
In php, there are many HTML tag methods to remove strings. The most common method is to use the strip_tags function together to retain only characters, the regular expression is also used in addition to selective removal. example 1: php built-in functions can be removed... in php, there are many HTML tag methods to remove strings. The most common method is to use the strip_tags function together to retain only characters, the regular expression is also used in addition to selective removal.

Example 1: Php built-in functions can remove/delete HTML tags/codes in strings:

Strip_tags (string, allow): The function removes HTML, XML, and PHP labels.

Parameters: String, required. it specifies the string to be checked, allow, optional. it specifies the tags that are allowed. these tags will not be deleted. the code is as follows:

$ Str = 'Guo bowl Basin-php'; $ str1 = strip_tags ($ str); // delete all HTML tags $ str2 = strip_tags ($ str ,''); // keep the tag echo $ str1; // output the Guo bowl Basin-PHP echo $ str2; // The style is different.

Example 2: Clear some attribute codes in the HTML tag string

Use PHP to process the HTML code of the document read from the database, and then use regular expressions to match and modify the code. Save the code and use the static generation function to generate the modified HTML page.

Because the generated code is already processed, the loading speed of the HTML page will not be affected. the specific code is as follows:

 

Related regular expressions: match any content: [sS] *.


Article link:

Save this article for favorites!

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.