title: Check to see if a string is encoded as UTF-8
body: <pre><code>function seems_utf8($str) {
   $length = strlen($str);
   for ($i=0; $i &lt; $length; $i++) {
    $c = ord($str[$i]);
    if ($c &lt; 0x80) $n = 0; # 0bbbbbbb
    elseif (($c &amp; 0xE0) == 0xC0) $n=1; # 110bbbbb
    elseif (($c &amp; 0xF0) == 0xE0) $n=2; # 1110bbbb
    elseif (($c &amp; 0xF8) == 0xF0) $n=3; # 11110bbb
    elseif (($c &amp; 0xFC) == 0xF8) $n=4; # 111110bb
    elseif (($c &amp; 0xFE) == 0xFC) $n=5; # 1111110b
    else return false; # Does not match any model
    for ($j=0; $j&lt;$n; $j++) { # n bytes matching 10bbbbbb follow ?
     if ((++$i == $length) || ((ord($str[$i]) &amp; 0xC0) != 0x80))
      return false;
    }
   }
   return true;
  }
  </code></pre>
  
  <p>I got this code from Wordpress, I don't know much about this, but I would like to know what exactly happing in that function. </p>
  
  <p>If any one know please help me out?</p>
  
  <p>I need the clear idea about the above code. If line by line explanation will be more helpful.</p>