How to find if a string contains all English or Arabic letters

I ask this question / answer further

How to check if php string contains only english letters and numbers?

but it skips checking for special characters, can we do this?

My goal is to find out if the string has Arabic characters, but it can be tricky ... (if not please tell).

Alternatively, we can check if it has all the English characters, otherwise it is obvious that it will be Arabic, since I have only these two languages ​​...

+5
source share
3 answers

You can search for Arabic characters with regular expression

$is_arabic = preg_match('/\p{Arabic}/', $text);

http://www.php.net/manual/en/regexp.reference.unicode.php

+5
source

If this does not work, try the following:

$is_arabic = preg_match('/\p{Arabic}/u', $text);

PHP preg-, PCRE, Unicode, /u http://www.regular-expressions.info/unicode.html.

+9

According to regular-expressions.info , PCRE does not necessarily support Unicode scripts. So take a closer look here about scripts

\p{Arabic} matches arabic characters

+1
source

All Articles