PHP Clear HTML-formatted Code _php tutorial

Source: Internet
Author: User
In the character interception is often due to HTML format unexpectedly, ASP is, PHP (as the mainstream development language now) Also, if the simple HTML format is predictable with replace on the line, for the body of the article may contain all the HTML format, want to efficient point or use the following, has been tested

$search = Array ("' Si",//Remove JavaScript
"' <[/!] *? [^<>]*?> ' Si ',//Remove HTML tags
"' ([RN]) [s]+ '",//Remove whitespace characters
"' & (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 (as the current mainstream development language) code

$replace = Array ("",
"",
"1",
""",
"&",
"<",
">",
" ",
Chr (161),
Chr (162),
Chr (163),
Chr (169),
"Chr (1)");
$document for a string to be processed if the source is a file can $document = file_get_contents ($filename);
$text = Preg_replace ($search, $replace, $document);

http://www.bkjia.com/PHPjc/509162.html www.bkjia.com true http://www.bkjia.com/PHPjc/509162.html techarticle in the character interception is often due to HTML format unexpectedly, ASP is, PHP (as the mainstream development language now) Also, if it is predictable simple HTML format with replace on the line, for the article ...

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