PHP three ways to remove HTML tags _php tutorial

Source: Internet
Author: User
Method 1:
Directly remove the mark you want to remove
Copy CodeThe code is as follows:
Remove BR Mark
function strip ($STR)
{
$str =str_replace ("
"," ", $str);
$str =htmlspecialchars ($STR);
Return Strip_tags ($STR);
}
?>

Method 2.
PHP has a strip_tags function that makes it easy to 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
In PHP, you can use the Strip_tags function to remove HTML tags, as shown in the following example:
Copy CodeThe code is as follows:
$str = ' www

Dreamdu

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

Method 3.
The STRTR () function converts a specific character in a string.
Grammar
STRTR (String,from,to)
or
STRTR (String,array)
parameter description
string1 required. Specifies the string to convert.
from
to
Array Required (unless using from and to). An array in which the key is the original character and the value is the target character.

Example 1:
Copy CodeThe code is as follows:
Echo strtr ("Hilla Warld", "ia", "eo");
?>

Example 2:
Copy CodeThe code is as follows:
$arr = Array ("Hello" = "Hi", "World" = "Earth");
Echo strtr ("Hello World", $arr);
?>

http://www.bkjia.com/PHPjc/327988.html www.bkjia.com true http://www.bkjia.com/PHPjc/327988.html techarticle Method 1: Directly remove the tag you want to remove the copy code code is as follows:? PHP//Remove BR tag function strip ($str) {$str =str_replace ("BR", "", $str);//$str = Htmlspecialchars ($STR); ....

  • 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.