PHP removes HTML tag instance _php instance

Source: Internet
Author: User
Example 1, PHP's own function can remove/delete the HTML tag/code in the string.
Strip_tags (String,allow): The function strips HTML, XML, and PHP tags.
Parameters: String, required, specifies the string to check, allow, optional, specify the allowed tags, these tags will not be deleted.
Copy the Code code as follows:
$str = ' Guo Bowl pot- PHP';
$str 1 = strip_tags ($STR); Delete all HTML tags
$str 2 = strip_tags ($str, " );//reserved label
echo $str 1; Output Guo Bowl scoop basin-php
echo $str 2; Not the same style!

Example 2, clearing some property codes in an HTML tag string
Using PHP to process the HTML code of the article read from the database, and then use regular code to match and modify, save the code, the static generation function can be generated after the modified HTML page.
Because the code we generate is code that has already been processed, it does not affect the loading speed of the HTML page.
The specific [sample code] is as follows:
Copy the Code code as follows:
$str = "";
$str = Preg_replace (' #onclick = ([ss]*) ' # ', ' ', $str);
#符号前面有一个双引号要注意, the code that represents the end
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.