开发者

PHP -Multibyte regular expression to remove all but chinese characters...please help

开发者 https://www.devze.com 2023-01-28 21:02 出处:网络
I am trying to take a UTF-8 string that looks something like: &q| 艝隭)R墢Lq28}徫廵g\'Y鑽妽踒F

I am trying to take a UTF-8 string that looks something like:

&q| 艝隭)R墢Lq28}徫廵g'Y鑽妽踒F

and strip out everything except the Chinese characters they are hex 4E00-9FA5 and I would like to keep only those characters in the string. I have tried taking this line that leaves only valid US characters:

preg_replace('/[^\x20-\x7E]/', '', $str);

to this:

preg_replace('/[^\x4E开发者_运维问答00-\x9FA5]/u', '', $str);

but it outputs nothing....am I missing something? I am not very good with regular expressions


You were very close!

preg_replace('/[^\x{4E00}-\x{9FA5}]/u', '', $str);
0

精彩评论

暂无评论...
验证码 换一张
取 消