开发者

PHP regex to to decipher English and Chinese characters

I have a descr开发者_运维技巧iption 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


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. ;)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜