/ Published in: PHP
I found this snippet in the FirePHP.class.php from www.firephp.org
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * Returns true if $string is valid UTF-8 and false otherwise. * * @param mixed $str String to be tested * @return boolean */ protected static function is_utf8($str) { $c=0; $b=0; $bits=0; for($i=0; $i<$len; $i++){ if($c > 128){ if(($c >= 254)) return false; elseif($c >= 252) $bits=6; elseif($c >= 248) $bits=5; elseif($c >= 240) $bits=4; elseif($c >= 224) $bits=3; elseif($c >= 192) $bits=2; else return false; if(($i+$bits) > $len) return false; while($bits > 1){ $i++; if($b < 128 || $b > 191) return false; $bits--; } } } return true; }
URL: www.firephp.org