0

I am trying to detect chinese characters in a string I have in PHP, currently I am trying to do this:

$bio = '全部都好有用架 無用的我都一早打入冷宮唔見哂(… 有意/想睇圖都歡迎留whatsapp or line: chibimasakishop 可綠線/將軍澳線交收';
    if (preg_match('/[\x{4e00}-\x{9fa5}]+.*\-/u', $bio) === 1) {
        var_dump('contains a chinese character');
    }

why isn't this working?

adit
  • 32,574
  • 72
  • 229
  • 373

2 Answers2

7

Try this

if(preg_match("/\p{Han}+/u", $bio))
{
  var_dump('contains a chinese character');
}  

Reference : Php check if the string has Chinese chars

Community
  • 1
  • 1
Satish Sharma
  • 9,547
  • 6
  • 29
  • 51
5

in your case i think you have "\-" extra, i think

/[\x{4e00}-\x{9fa5}]+.*/u

should work

Jacky Cheng
  • 1,536
  • 1
  • 10
  • 22
  • This won't detect Chinese characters accurately. Some characters are treated non-Chinese characters. – Raptor Nov 14 '16 at 07:39