php – Allow English characters, Chinese, Japanese-ThrowExceptions

Exception or error:

How I can replace only the symbols via PHP but not the characters what is numbers 0,9 or English or Chinese or Japanese characters only symbols. Is there any way to do this via PHP?

I use preg_replace to allow English characters and numbers but if Japanese/Chinese/Russians characters are found is auto-deleted.

I try this command too but it is still not working:

$Data             = preg_replace('/[^\p{L}\p{N}]/u', '-', $Data);
How to solve:

May be this code will help you.

$string = "年m月d日ASDFdfdfd4545$@#$@$@";

$newString = preg_replace('/[^\\p{L} 0-9]/mu', "_", $string);

echo $newString;



  • \p{L} matches any kind of letter from any language

  • /u is the Unicode modifier, you need this if you want to handle
    Unicode characters

Live demo:

Leave a Reply

Your email address will not be published. Required fields are marked *