Three methods for deleting html tags in php-php Tutorial

Source: Internet
Author: User
How php deletes html tags
This article introduces three methods to delete html tags using php. For more information, see.

Method 1: directly retrieve the desired tag. Use php functions: str_replace, htmlspecialchars, and strip_tags.

     "," ", $ Str); // $ str = htmlspecialchars ($ str); return strip_tags ($ str) ;}?>

Method 2: there is a strip_tags function in PHP that can easily remove HTML tags. Echo strip_tags ("HelloWorld"); // Remove HTML, XML, and PHP labels. You can also correctly remove non-standard HTML code: echo strip_tags ("\"> cftea "); // output cftea

Use the strip_tags function to remove HTML tags.

     dreamdu

.com';echo(htmlspecialchars($str).”
”);echo(strip_tags($str));?>

Method 3: Use the strtr function to convert specific characters in a string. The strtr (string, from, to) or strtr (string, array) parameters are required to describe string1. Specifies the string to be converted. From is required (unless an array is used ). Specifies the character to be changed. To is required (unless an array is used ). Specifies the character to be changed. Array is required (unless from and to are used ). An array where the key is the original character and the value is the target character.

Example 1:

     

Example 2:

      "Hi", "world" => "earth");echo strtr("Hello world",$arr);?>
Articles you may be interested in: php: two ways to remove HTML tags php: remove excessive HTML tags php uses strip_tags to completely remove all html tags example of how php filters html tags using strip_tags) php code for deleting html tags and html tags in strings php for removing the difference between strip_tags and htmlspecialchars for html tags php function for deleting html tags in strings extracting html tags from html tags php code php regular filtering html tags, spaces, line breaks, and other code examples php removes html tags to obtain the input text document strip_tagsphp, so that HTML tags are automatically completed and closed function code php implements html tags automatically how to use the Html template tag of the supplemented code thinkPHP

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.