Home >Backend Development >PHP Tutorial >PHP filter string function_PHP tutorial

PHP filter string function_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:31:191150browse

分享一个php过滤字符串函数,具体代码如下:

function StripHTML($string){
	$pattern=array ("'<script[^>]*?>.*?</script>'si", "'<style[^>]*?>.*?</style>'si",  "'<[\/\!]*?[^<>]*?>'si",  "'([\r\n])[\s]+'",  "'&(quot|#34);'i",  "'&(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");
	$replace=array ('', '', "\\1", '', "&", "<", ">", ' ', chr(161), chr(162), chr(163), chr(169), "chr(\\1)");
	return preg_replace ($pattern, $replace, $str);
}

您可能感兴趣的文章

  • php被遗忘的一些功能强大的字符串处理函数
  • php最精确的字符串长度截取函数
  • php字符串替换函数str_replace速度比preg_replace快
  • PHP中的字符串处理函数(String Functions) 全总结
  • PHP 字符串转义函数(addslashes,stripslashes)详解
  • js数组转字符串,js字符串转数组的方法总结
  • php提取字符串中的数字
  • PHP 生成连续的数字(字母)数组函数range()分析,PHP抽奖程序函数

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/764104.htmlTechArticle分享一个php过滤字符串函数,具体代码如下: function StripHTML($string){$pattern=array ("'script[^]*?.*?/script'si", "'style[^]*?.*?/style'si", "'[\/\!]*?[^]*?'si"...
Statement:
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