title: Detect charset of string in PHP (UTF-8 or Windows-1256)
body: <p><br>
  I'm working on script based on "<a href="http://simplehtmldom.sourceforge.net/" rel="nofollow">Simple HTML DOM</a>" and I want to detect string's charset after getting inner text of URL to convert it to "UTF-8" using <code>iconv()</code>.<br>
  I've tried a lot of things but non of them work with <code>Windows-1256</code>.<br>What I've tried:-<br></p>
  
  <p><code>mb_detect_encoding($content)</code> detects <code>Windows-1256</code> as <code>UTF-8</code><br>
  <code>mb_detect_encoding($content, "windows-1256")</code> gives an error <code>Illegal argument</code><br></p>
  
  <pre><code>function is_utf8($string) {   
    return preg_match('%^(?:  
    [\x09\x0A\x0D\x20-\x7E] # ASCII  
    | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte  
    | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs  
    | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte  
    | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates  
    | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3  
    | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15  
    | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16  
    )*$%xs', $string);
  }
  </code></pre>
  
  <p>This function returns "0" if not UTF-8 but when string is UTF-8 it returns "Page can not be found". I'm not sure why!<br>
  My code is:<br></p>
  
  <pre><code>$html = file_get_html($url);
  foreach($html-&gt;find('div[id=content]') as $element) {
    $content = $element-&gt;innertext;
    #Detect charset encoding of $content
  }
  </code></pre>
  
  <p>URLs I'm working with:<br>
  UTF-8: <a href="http://www.masrawy.com/news/Egypt/Politics/2013/March/3/5541050.aspx" rel="nofollow">http://www.masrawy.com/news/Egypt/Politics/2013/March/3/5541050.aspx</a><br>
  Windws-1256: <a href="http://www.youm7.com//News.asp?NewsID=965545" rel="nofollow">http://www.youm7.com//News.asp?NewsID=965545</a></p>