Three solutions for php to delete html tags: phphtml labels

Source: Internet
Author: User

Three solutions for php to delete html tags: phphtml labels

This article describes three methods for deleting HTMl tags in PHP.

Method 1:
Directly retrieve the tag

<? Php // remove the br Flag function strip ($ str) {$ str = str_replace ("<br>", "", $ str ); // $ str = htmlspecialchars ($ str); return strip_tags ($ str);} // edit by www.jbxue.com?>

Method 2.

PHP has a strip_tags function to easily remove HTML tags.
Echo strip_tags ("Hello <B> World </B>"); // remove HTML, XML, and PHP labels.
Non-standard HTML code can also be correctly removed:
Echo strip_tags ("<a href = \"> cftea </a> "); // output cftea
In PHP, you can use the strip_tags function to remove HTML tags. See the following example:

<?php$str = ‘www.<p>jbxue</p>.com';echo(htmlspecialchars($str).”<br>”);echo(strip_tags($str));?>

Method 3.

The strtr () function converts special characters in a string.
Syntax
Strtr (string, from,)
Or
Strtr (string, array)
Parameter description
String1 is required. 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:

<?phpecho strtr("Hilla Warld","ia","eo");?>

Example 2:

<?php$arr = array("Hello" => "Hi", "world" => "earth");echo strtr("Hello world",$arr);?>

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.