Advertisement
Guest User

Untitled

a guest
Dec 13th, 2011
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. function isUtf8($string)
  2. {
  3.     if (is_object($string))
  4.     {
  5.         throw new Exception('Input cannot be an object!');
  6.     }
  7.  
  8.     elseif (is_array($string))
  9.     {
  10.         foreach($string as $key => $value)
  11.         {
  12.             if (!strings_is_utf8($value))
  13.                 return false;
  14.         }
  15.  
  16.         return true;
  17.     }
  18.  
  19.     return preg_match('%(?:
  20.                         [\xC2-\xDF][\x80-\xBF]                 # non-overlong 2-byte
  21.                         |\xE0[\xA0-\xBF][\x80-\xBF]            # excluding overlongs
  22.                         |[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}     # straight 3-byte
  23.                         |\xED[\x80-\x9F][\x80-\xBF]            # excluding surrogates
  24.                         |\xF0[\x90-\xBF][\x80-\xBF]{2}         # planes 1-3
  25.                         |[\xF1-\xF3][\x80-\xBF]{3}             # planes 4-15
  26.                         |\xF4[\x80-\x8F][\x80-\xBF]{2}         # plane 16
  27.                         )+%xs', $string);
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement