开发者

Detect chinese (multibyte) character in the string

开发者 https://www.devze.com 2022-12-08 09:56 出处:网络
$str = \"This is a string containing 中文 characters. Some more characters - 中华人民共和国 \";
$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 fi开发者_高级运维rst character and ends with "-"? (it would be "中文 characters. Some more characters -").

Thank you!


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


Is PHP storing this as Unicode? If so, at worst you could step through the string, character by character, until you hit those within the Chinese range.

Check this out too PHP: Unicode - Manual

0

精彩评论

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