This question already has an answer here:
I have a string like this :
این یafsک رشsegته می y34باشد
Specially , i want a function (like regex) to echo out JUST persian chars.
So , the out put should be :
این یک رشته می باشد
I have found we can use below regex, but i can't use it with function, it does not work.
regex i tried:
preg_match("(^[\x{0600}-\x{06FF}]*$)", $title);
error : Compilation failed: character value in \x{} or \o{} is too large at offset
What can i do and what should i do ?
Tnx.
</div>
سلام عزیزم
$string = preg_replace("/[a-zA-Z0-9]/", "", $string);
You can simply remove all English alphabetical characters and all numbers from the string
OR : you can do it reverse :
$string = preg_replace("/[^ الف-ی]/i", "", $string);
This will remove all characters except Persian chars , This way you can remove all persian numbers too : d
You need to enable UTF-8 on the pattern to use the “higher” unicode range in a regex:
preg_match("/^[\x{0600}-\x{06FF}]*$/u", $title);
Note the u
modifier after the closing delimiter.
Try this one:
preg_match("/^[الف-ی]*$/u", $title);