PHP regex to to decipher English and Chinese characters

余生颓废 提交于 2019-12-24 05:18:12

问题


I have a description which is in English and Chinese.

How would I go about using regex to say something like, if the line contains a Chinese character then do A, else do B ?

example here

电源: 110V/220W50-60HZ
功率:60W
光源:12V 150 W
尺寸:220x150x280mm
重量:2.3KG



Voltage : 110V/220W50-60HZ
Power : 60W
Bulb : 12V 150 W
Size : 220x150x280mm
Weight:2.3KG

回答1:


Chinese characters are within the range: U+4E00..U+9FFF

If your expreg extension has been built with Unicde support, b\p{InCJK_Unified_Ideographs} is a good replacement for [\x{4E00}-\x{9FFF}] (which was in the link Jens Struwe gave).

You can find most (all?) of Unicode ranges here: http://www.regular-expressions.info/unicode.html

I'm not sure what you want to achieve, but maybe a good start would be split your description by line. Then, for each line, find whether it's Chinese or not, and run the appropriate regex. ;)



来源:https://stackoverflow.com/questions/6882967/php-regex-to-to-decipher-english-and-chinese-characters

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!