aul*_*ron 52
$str = preg_replace('/[^\00-\255]+/u', '', $str);
Run Code Online (Sandbox Code Playgroud)
您最好的选择是使用iconv,它将字符串转换为请求的字符编码.
iconv('UTF-8', 'ASCII//TRANSLIT', $yourtext);
Run Code Online (Sandbox Code Playgroud)
随着//translit你得到一个有意义的转换为ASCII(例如ß - > ss).使用// IGNORE将完全删除非ascii字符.
iconv('UTF-8', 'ASCII//IGNORE', $yourtext);
Run Code Online (Sandbox Code Playgroud)
见http://php.net/manual/en/function.iconv.php
通过使用preg_replace()
$string = "some ???? text";
$string = preg_replace('/[^a-z0-9_ ]/i', '', $string);
echo $string;
Run Code Online (Sandbox Code Playgroud)
当然,您需要扩展preg_replace模式,但这是一种方法.可能有更好的方法,我只是不知道.