I have the string $str
and I want to check if it`s content has Chinese chars or not (true/false)
$str = "赕就可消垻,只有当所有方块都被消垻时才可以过关";
can you please help me?
Thanks! Adrian
In PHP, regular expressions are strings composed of delimiters, a pattern and optional modifiers. $exp = "/w3schools/i"; In the example above, / is the delimiter, w3schools is the pattern that is being searched for, and i is a modifier that makes the search case-insensitive.
The chinese is a MULTIBYTE character and only UTF8 can handle this. and store the chinese characters in a NCLOB or NVARCHAR2 data types.
Chinese characters, 漢字 (simplified 汉字), are known by many names: “Sinograms” (from the Greek name of China), “Hànzì” (from Mandarin), “Hanja” (from Korean 한자), and “Kanji” (from Japanese かんじ). Whatever you prefer to call them, they are the most complex writing system in use today.
PHP has a built-in support for regular expressions too. In PHP, there are two modules for regular expressions: the POSIX Regex and the PCRE. The POSIX Regex is depreciated. In this chapter, we will use the PCRE examples.
You could use a unicode character class http://www.regular-expressions.info/unicode.html
preg_match("/\p{Han}+/u", $utf8_str);
This just checks for the presence of at least one chinese character. You might want to expand on this if you want to match the complete string.
@mario
answer is right!
For Chinese chars use this regex: /[\x{4e00}-\x{9fa5}]+/u
And Don't forget the u
modifier!!!
About u
modifier reference
TKS to mario
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With