将HTML标签正则替换为:这[内容]是什么意思?
- 内容介绍
- 文章标签
- 相关推荐
本文共计150个文字,预计阅读时间需要1分钟。
复制代码+代码如下:phpfunction pregstring($str) { $strtemp=trim($str); $search=array( /\|'/, /]*>/i, /\[[^\]]*\]/, /\[\/\![^\]]*\]/, '' ); return preg_replace($search, '', $strtemp);}
<?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(字符串); //使用方法
?>
本文共计150个文字,预计阅读时间需要1分钟。
复制代码+代码如下:phpfunction pregstring($str) { $strtemp=trim($str); $search=array( /\|'/, /]*>/i, /\[[^\]]*\]/, /\[\/\![^\]]*\]/, '' ); return preg_replace($search, '', $strtemp);}
<?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(字符串); //使用方法
?>

![将HTML标签正则替换为:这[内容]是什么意思?](/imgrand/VzaZ0baa.webp)