Regular replacement of PHP HTML tags and customizable regular rules

Time:2021-4-10
Copy codeThe code is as follows:
<?php
function pregstring($str){
$strtemp = trim($str);
$search = array(
“|’|Uis”,
“| < script [^ >]. *? < / script > | UIs”, / / remove JavaScript
“| [word definition]. * \ [/ word definition] | UIs”, / / remove the thumbnail
“| < [\ / \!]. *? [^ < >] *? > | UIs”, / / remove the HTML tag
“‘> (quot | 34);’I’, / / replace HTML entity
“‘>(amp|#38);’i”,
“|,|Uis”,
“|[\s]{2,}|is”,
“[>nbsp;]isu”,
“|[$]|Uis”,
);
$replace = array(
“`”,
“”,
“”,
“”,
“”,
“”,
“”,
” “,
” “,
” “,
);
$text = preg_replace($search, $replace, $strtemp);
return $text;
}
Echo pregstring (string); / / usage
?>