Php clear HTML code _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Php clears HTML code. When intercepting characters, it is often caused by exceptions in the HTML format. ASP is, php (as the mainstream development language) is also, if it is a foreseeable simple HTML format, use replace, for articles that often encounter exceptions in the HTML format due to character truncation, ASP is, php (as the mainstream development language) is also, for the foreseeable simple HTML format, you can use replace. for the article body, which may contain all the HTML formats, you can use the following method for efficiency.

$ Search = array ("' ] *?>. *? Script 'Si ", // remove javascript
"'<[/!] *? [^ <>] *?> 'Si ", // remove the HTML tag
"'([Rn]) [s] +'", // remove the white space
"'& (Quot | #34);' I", // replaces the HTML object
"'& (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 the code as php (as the mainstream development language ).

$ Replace = array ("",
"",
"1 ",
""",
"&",
"<",
"> ",
"",
Chr (1, 161 ),
Chr (1, 162 ),
Chr (1, 163 ),
Chr (1, 169 ),
"Chr (1 )");
// $ Document is the string to be processed. if the source is a file, you CAN $ document = file_get_contents ($ filename );
// $ Text = preg_replace ($ search, $ replace, $ document );

Pipeline (as the mainstream development language) is also, if it is a foreseeable 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.