Scooter Daraf Scooter Daraf - 1 year ago 88
PHP Question

Detect mixed language php

i know how to detect only arabic letters by this

$string = " هذه اللغة العربية";
if (preg_match('/^[A-Za-z]/', $string)){}else{ // is arabic

I knowhow to detect only english letters

$string ="This is english language" ;
if (preg_match('/^[A-Za-z]/', $string)) { // is english

BUT if its mixed it detect it as arabic .

$string = "this is عربية" ;
if (preg_match('/^[A-Za-z]/', $string)) { }else { // is arabic

What i want is when its mixed then detect it as english NOT arabic .

AND how to add these symbols also
so when

$string = "@اتااتاتانت" ; // it will be also detected as english


Answer Source

Following your logic, all you need is to check if a string contains an ASCII letter:

if (preg_match('~[a-z]~ui', $input)) { 
   echo "It is NOT Arabic"; 

You do not even use \p{Arabic} here.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download