2

How to detect other language except english in string php ?

I use this code for detect other language beside english.

i want to know how can i reduce my code for short and cover all language.

<?PHP
$utf8_str = "xxxxxxxxxxxxxxx";
$Common = preg_match("/\p{Common}+/u", $utf8_str);
$Arabic = preg_match("/\p{Arabic}+/u", $utf8_str);
$Armenian = preg_match("/\p{Armenian}+/u", $utf8_str);
$Bengali = preg_match("/\p{Bengali}+/u", $utf8_str);
$Bopomofo = preg_match("/\p{Bopomofo}+/u", $utf8_str);
$Braille = preg_match("/\p{Braille}+/u", $utf8_str);
$Buhid = preg_match("/\p{Buhid}+/u", $utf8_str);
$Canadian_Aboriginal = preg_match("/\p{Canadian_Aboriginal}+/u", $utf8_str);
$Cherokee = preg_match("/\p{Cherokee}+/u", $utf8_str);
$Cyrillic = preg_match("/\p{Cyrillic}+/u", $utf8_str);
$Devanagari = preg_match("/\p{Devanagari}+/u", $utf8_str);
$Ethiopic = preg_match("/\p{Ethiopic}+/u", $utf8_str);
$Georgian = preg_match("/\p{Georgian}+/u", $utf8_str);
$Greek = preg_match("/\p{Greek}+/u", $utf8_str);
$Gujarati = preg_match("/\p{Gujarati}+/u", $utf8_str);


if(($Common != '0') OR ($Arabic != '0') OR ($Armenian != '0') OR ($Bengali != '0') OR ($Bopomofo != '0') OR ($Braille != '0') OR ($Buhid != '0') OR ($Canadian_Aboriginal!= '0') OR ($Cherokee != '0') OR ($Cyrillic != '0') OR ($Devanagari != '0') OR ($Ethiopic != '0') OR ($Georgian != '0') OR ($Greek != '0') OR ($Gujarati != '0'))
{
    echo "have other language";
}
else
{
    echo "Only english";
}
?>
poretu terdi
  • 89
  • 1
  • 7
  • 2
    Possible duplicate of [Detect language from string in PHP](http://stackoverflow.com/questions/1441562/detect-language-from-string-in-php) – robere2 Dec 21 '16 at 14:06

1 Answers1

0

Internationalization is something that takes much more time than a simple regex. Check this out, https://lingohub.com/blog/2013/07/internationalization-how-to-5-most-popular-php-frameworks/

Miguel Coder
  • 1,896
  • 19
  • 36