欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

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
;
}