5

I'm taking this question/answer further

How to check, if a php string contains only english letters and digits?

but it's missing special characters check, can we do that?

My objective is to find out if the string has arabic characters but that might be difficult... (if not please advise).

Alternatively we can check if it has all english characters otherwise obviously it would be arabic since I've these two languages only...

Community
  • 1
  • 1

3 Answers3

10

If it doesn't work, try the following:

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

The PHP preg functions, which are based on PCRE, support Unicode when the /u option is appended to the regular expression, as per http://www.regular-expressions.info/unicode.html.

Caio Almeida
  • 286
  • 4
  • 6
5

You can look for Arabic characters with regexp

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

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

gintas
  • 2,118
  • 1
  • 18
  • 28
1

According to regular-expressions.info, PCRE is optionally supporting Unicode scripts. So have a closer look here about scripts

\p{Arabic} is matching Arabic characters

stema
  • 90,351
  • 20
  • 107
  • 135