PHP的一个字符过滤函数
程序员文章站
2024-01-31 22:31:46
...
函数
function safe_convert($string, $html=0) { //Words Filter
if ($html==0) {
$string=htmlspecialchars($string, ENT_QUOTES);
$string=str_replace(",",$string);
$string=str_replace(">",">",$string);
$string=str_replace("\\", '\', $string);
} else {
$string=addslashes($string);
$string=str_replace("\\\\", '\', $string);
}
$string=str_replace("\r","
",$string);
$string=str_replace("\n","",$string);
$string=str_replace("\t"," ",$string);
$string=str_replace(" "," ",$string);
$string=str_replace('|', '|', $string);
$string=str_replace("`","`",$string);
$string=str_replace("\","\",$string);
return $string;
}