PHP clears HTML formatted code_PHP tutorial

WBOY
Release: 2016-07-13 17:30:30
Original
898 people have browsed it

When character interception, accidents often occur due to the HTML format. ASP is the case, and php(as the current mainstream development language) is the same. If it is a foreseeable and simple HTML format, just use replace. For the article text, The class may contain all HTML formats. If you want to be more efficient, use the following. Tested

$search = array ("']*?>.*?< /script>'si", // Remove javascript
"'<[/!]*?[^<>]*?>'si", // Remove HTML tags
"'( [rn])[s]+'", "'&(quot|#34);'i", //Remove whitespace characters
"'&(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"); Current mainstream development languages)
Code running$replace = array ("",
                                                                                          
"& ",
                "<",
                                                                                                       
chr(162),
chr(163),
chr(169),
"chr(1)");
//$document is a string that needs to be processed. If the source is a file, $document = file_get_contents($filename);
//$ text = preg_replace($search, $replace, $document);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/509162.htmlTechArticleWhen character interception, accidents often occur due to HTML format, ASP, PHP (as the current mainstream development language) Also, if it is a predictable and simple HTML format, just use replace. For articles...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!