简体   繁体   中英

PHP regex to to decipher English and Chinese characters

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM