因此,我制作了这个刮刀,它从多个站点返回字符串。我想检查字符串是否匹配,所以我使用php来清理字符串并检查。然而,&和其他特殊字符以两种方式出现,一种是&,另一种是&。我该如何去除每一种类型。
preg_replace("/[^a-zA-Z0-9]+/", "", $string);我已经有了,但这不排除特殊的角色。
谢谢。
发布于 2013-07-21 21:01:45
尝尝这个
function removeSpecialChar($string) {
$string = str_replace('', '-', $string); // Replaces all spaces with hyphens.
return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
}
echo removeSpecialChar(html_entity_decode('&khawer&')); //will output khawer发布于 2013-07-21 21:00:28
我想你是在找htmlspecialchars()函数。
运行您的字符串以及strip_tags()和strip_slashes()应该会清理您的字符串。
htmlspecialchars(strip_tags(strip_slashes($string)));
https://stackoverflow.com/questions/17776803
复制相似问题