Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

$str = "This is a string containing 中文 characters. Some more characters - 中华人民共和国 ";

How do I detect chinese characters from this string and print the part which starts with the first character and ends with "-"? (it would be "中文 characters. Some more characters -").

Thank you!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
700 views
Welcome To Ask or Share your Answers For Others

1 Answer

I've solved this problem using preg_match and regular expressions:

$str = "This is a string containing 中文 characters. Some more characters - 中华人民共和国 ";

preg_match(/[x{4e00}-x{9fa5}]+.*-/u, $str, $matches);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...