PHP removes HTML tag instance _php instance

Source: Internet
Author: User
Tags html tags

Example 1, PHP's own functions can remove/remove HTML tags/code in the string.
Strip_tags (String,allow): Functions strip HTML, XML, and PHP tags.
Parameters: String, required, specify the strings to be checked, allow, optional, specify the labels that are allowed to exist, and these tags will not be deleted.

Copy Code code as follows:

$str = ' Guo Bowl ladle-<span style= ' color: #f00; >PHP</span> ';
$str 1 = strip_tags ($STR); Delete all HTML tags
$str 2 = strip_tags ($str, ' <span> '); Reservations <span> Labels
echo $str 1; Output Guo Bowl scoop basin-php
echo $str 2; It's not the same style!

Example 2, clear some of the property codes in the HTML tag string
Use PHP to process the text from the database read the HTML code, and then use the regular code to match and modify, save the code, with the static build function can be generated after the modified HTML page.
Because the code we generate is code that has been processed, it does not affect the speed at which HTML pages are loaded.
Specific [sample code] is as follows:

Copy Code code as follows:

<?php
$str = "$str = Preg_replace (' #onclick = ([ss]*) ' # ', ', $str];
#符号前面有一个双引号要注意, representing the end of the code
Print ($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.