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
  • 30,916
  • 67
  • 221
  • 365

2 Answers2

6

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,475
  • 6
  • 27
  • 51
5

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

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

should work

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