[英]Remove � Special Character from String
我一直在尝试使用PHP从html字符串流中删除垃圾字符,但尚未成功。 有什么特殊的语法或逻辑可以从字符串中删除特殊字符吗?
到目前为止,我已经尝试过了,但是没有用
$new_string = preg_replace("�", "", $HtmlText);
echo '<pre>'.$new_string.'</pre>';
\p{S}
您可以使用它。 \\p{S} matches math symbols, currency signs, dingbats, box-drawing characters, etc
参见演示。
https://www.regex101.com/r/rK5lU1/30
$re = "/\\p{S}/i";
$str = "asdas�sadsad";
$subst = "";
$result = preg_replace($re, $subst, $str);
这是由于数据库和前端之间的字符集不匹配所致。 更正此问题将解决此问题。
函数clean($ string){
return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.