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.

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

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

echo $newString;

Output:

年m月d日ASDFdfdfd4545_______

  • \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: http://sandbox.onlinephpfunctions.com/code/a81db5a33e910799f995046104d38898c1203756

Leave a Reply

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