$STR = ' abc ... 1 ... Good...... (... 234*& (*&)) ( ※ o (∩_∩) o ha! √ (⊙o⊙)? '; Filtering other special symbols in addition to English and Chinese characters $tmp = Str_replace ($REPLACEARR, ", $str); $tmp 1 = preg_replace ('/(?! [A-za-z\\x{4e00}-\\x{9fa5}]) /', ', $str); This is the actual requirement $tmp 2 = preg_replace ('/([\\x80-\\xff])/', ', $str); This is the filter kanji $tmp 3 = preg_replace ('/[\\x{4e00}-\\x{9fa5}]/u ', ' ', $str); This is also filtering Chinese characters "; Var_dump ($tmp); Echo '
'; "; Var_dump ($tmp 1); Echo '
'; "; Var_dump ($tmp 2); Echo '
'; "; Var_dump ($tmp 3); Echo '
'; Expected Result: ABC good
Current code execution result (all wrong)
Ask you to be the great God, or there are other better ways.
Main purpose: Replace non-English letters and other symbols of non-Chinese characters in strings with null. Default encoding: GB2312
Reply to discussion (solution)
$STR = ' abc ... 1 ... Good...... (... 234*& (*&)) ( ※ o (∩_∩) o ha! √ (⊙o⊙)? '; $str = Iconv (' GBK ', ' utf-8 ', $str); $str = preg_replace ('/[\w_]/u ', ' ', $str); $str = Iconv (' utf-8 ', ' GBK ', $str); Echo $st R
ABC1 good 234OO ha o
Like Sogou expression in the special symbol, still can't filter out?
That looks like a letter, I got it wrong!
Thanks to Xu for his great support!
Moderator, I just overlooked a problem, I follow your code to run the results, is no kanji: