当前位置: 移动技术网 > IT编程>开发语言>正则 > PHP html标签正则替换并可自定义正则规则

PHP html标签正则替换并可自定义正则规则

2017年12月12日  | 移动技术网IT编程  | 我要评论
复制代码 代码如下:

<?php
function pregstring($str){
$strtemp = trim($str);
$search = array(
"|'|uis",
"|<script[^>].*?</script>|uis", // 去掉 javascript
"|\[字定义\].*\[/字定义\]|uis", // 去掉缩略图
"|<[\/\!].*?[^<>]*?>|uis", // 去掉 html 标记
"'>(quot|#34);'i", // 替换 html 实体
"'>(amp|#38);'i",
"|,|uis",
"|[\s]{2,}|is",
"[>nbsp;]isu",
"|[$]|uis",
);
$replace = array(
"`",
"",
"",
"",
"",
"",
"",
" ",
" ",
" ",
);
$text = preg_replace($search, $replace, $strtemp);
return $text;
}
echo pregstring(字符串); //使用方法
?>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网