title: Check the language of string based on glyphs in PHP
body: <p>I have a MySQL database with book titles in both English and Arabic and I'm using a <a href="http://www.ar-php.com/php/arabic/index.html" rel="nofollow noreferrer">PHP class</a> that can automatically transliterate Arabic text into Latin script.</p>
  
  <p>I'd like my output HTML to look something like this:</p>
  
  <pre><code>&lt;h3&gt;A book&lt;/h3&gt;
  &lt;h3&gt;كتاب &lt;em&gt;(kitaab)&lt;/em&gt;&lt;/h3&gt;
  &lt;h3&gt;Another book&lt;/h3&gt;
  </code></pre>
  
  <p>Is there a way for PHP to determine the language of a string based on the Unicode characters and glyphs used in it? I'm trying to get something like this:</p>
  
  <pre><code>$Ar = new Arabic('EnTransliteration');
  while ($item = mysql_fetch_array($results)) {
      ...
      if (some test to see if $item['item_title'] has Arabic glyphs in it) {
        echo "&lt;h3&gt;$item[item_title] &lt;em&gt;(" . $Ar-&gt;ar2en($item['item_title']) . ")&lt;/em&gt;&lt;/h3&gt;";
      } else {
        echo "&lt;h3&gt;$item[item_title]&lt;/h3&gt;";
      }
      ...
  }
  </code></pre>
  
  <p>Fortunately the class doesn't choke when fed Latin characters, so in theory I could send every result through the transformation, but that seems like a waste of processing.</p>
  
  <p>Thanks!</p>
  
  <p><strong>Edit:</strong>
  I still haven't found a way to check for glyphs or characters. I suppose I could put all the Arabic characters in an array and check if anything in the array matches a part of the string...</p>
  
  <p>I did, however, figure out an interim solution that might work fine in the end. It puts every title through the transformation regardless of language, but only outputs the parenthetical transliteration if the string was changed:</p>
  
  <pre><code>while ($item = mysql_fetch_array($mysql_results)) {
      $transliterate = trim(strtolower($Ar-&gt;ar2en($item['item_title'])));
      $item_title = (strtolower($item['item_title']) == $transliterate) ? $item['item_title'] : $item['item_title'] . " &lt;em&gt;($transliterate)&lt;/em&gt;";
  
      echo "&lt;h3&gt;$item_title&lt;/h3&gt;";
  }
  </code></pre>