[转] php 去除html

WBOY
Release: 2016-06-23 14:30:43
Original
1105 people have browsed it

转载自: http://blog.sina.com.cn/s/blog_54318f230100mv46.html

function replaceHtmlAndJs($document){$document = trim($document);if (strlen($document) <= 0){  return $document;}$search = array ("'<script[^>]*?>.*?</script>'si",  // 去掉 javascript                  "'<[\/\!]*?[^<>]*?>'si",          // 去掉 HTML 标记                  "'([\r\n])[\s]+'",                // 去掉空白字符                  "'&(quot|#34);'i",                // 替换 HTML 实体                  "'&(amp|#38);'i",                  "'&(lt|#60);'i",                  "'&(gt|#62);'i",                  "'&(nbsp|#160);'i"                  );                    // 作为 PHP 代码运行$replace = array ("",                   "",                   "\\1",                   "\"",                   "&",                   "<",                   ">",                   " "                   );return @preg_replace ($search, $replace, $document);}
Copy after login



Related labels:
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