PHP is to remove all the html,js,css in the Web page, the annotation implementation method _php instance

Source: Internet
Author: User
Tags chr html tags

As shown below:

$search = Array ("' <script[^>]*?>.*?</script> ' si",//Remove JavaScript
 "' <style[^>]*?>.*?) </style> ' Si ',  //Remove CSS '
 <[/!] *? [^<>]*?> ' Si ',      //Remove HTML Tags
 "' <!--[/!] *? [^<>]*?> ' Si ',//      Remove comment Mark
 "' ([RN]) [s]+ '",  //Remove white space character
 "' & (quot| #34); ' I ",  //Replace HTML entity

 " ' & (amp| #38); ' I ",
 " ' & (lt| #60); ' I ",
 " ' & (gt| #62); ' I ",
 " ' & (nbsp| #160); ' I ",
 " ' & (iexcl| #161); ' I ",
 " ' & (cent| #162); ' I ",
 " ' & (pound| #163); ' I ",
 " ' & (copy| #169); ' I ",
 " ' &# (d+); ' E ");   Run as PHP code
 
$replace = Array ("",
 "", ""
 ,
 "" ",
 " \1 ",
 " \ "",
 "&",
 "<" , 
 ">",
 "" ",
 chr (161),
 Chr (162),
 Chr (163),
 Chr (169),
 " Chr (\1) ");
$document for strings to be processed if the source is a file can $document = file_get_contents ($filename);
$out = Preg_replace ($search, $replace, $document);

You can also use PHP's built-in function strip_tags () to clear html,js, annotations, and so on.

The above is a small series for everyone to bring PHP is to remove all the html,js,css in the Web page, the annotation of the implementation of all the content, I hope that we support cloud-Habitat Community ~

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.