Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Chinese Characters with Preg_replace?

Tags:

php

I am trying to remove chinese characters from string. Tried this but can't get this working. It says:

Warning: preg_replace() [function.preg-replace]: Compilation failed: character value in \x{...} sequence is too large at offset 9 in

preg_replace('/[^\x{4e00}-\x{9fa5}]+/', '', $string)

How can I get this working ?

like image 216
user198989 Avatar asked Jan 23 '26 05:01

user198989


1 Answers

In UTF-8 mode, "\x{...}" is allowed, where the contents of the braces is a string of hexadecimal digits.

You don't appear to be in UTF-8 mode. To enable this mode, add the u modifier to the end of the regex.

like image 77
Niet the Dark Absol Avatar answered Jan 24 '26 17:01

Niet the Dark Absol



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!