PHP three ways to delete HTML tags share

Source: Internet
Author: User
This article describes the use of PHP to remove HTML tags three ways, with the need for friends, refer to the next bar.

Method 1, remove the desired tag directly. PHP functions are used: Str_replace, Htmlspecialchars, Strip_tags.

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

The 2,php method has a strip_tags function to easily remove HTML tags. Echo strip_tags ("Hello World"); Remove HTML, XML, and PHP tags. For non-standard HTML code can also be correctly removed: Echo strip_tags ("\" >cftea "); Output Cftea

Use the Strip_tags function to remove HTML tags.

 
      Dreamdu

. com '; Echo (Htmlspecialchars ($STR). "
"); Echo (Strip_tags ($STR));? >

The 3,strtr method converts a specific character in a string to a function. Syntax Strtr (string,from,to) or STRTR (string,array) parameter description string1 required. Specifies the string to convert. From required (unless an array is used). Specifies the character to be changed. To required (unless an array is used). Specifies the character to change to. Array is required (unless you use from and to). An array in which 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); >
You may be interested in the article: PHP two ways to remove HTML tags PHP remove redundant HTML tags PHP with strip_tags complete removal of all HTML tags of the instance share PHP filter HTML tag function Strip_tags usage example (graphic) PHP Remove HTML tags and HTML tags in the code PHP HTML markup to remove the strip_tags and htmlspecialchars of the difference between the PHP delete the HTML tags in the function to remove the content of HTML Tag code extract HTML tag PHP code PHP regular filter HTML tags, spaces, line breaks, etc. code sample PHP Remove HTML tags get input plain text document STRIP_ tagsphp Make HTML tags auto-complete closed function code PHP implementation HTML tag Auto-complete code thinkphp HTML template Tag use method
  • Related Article

    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.