function detect Unicode UTF-8 string PHP

Based upon that snippet below using preg_match() I needed something faster and less specific.  That function works and is brilliant but it ...

Based upon that snippet below using
preg_match() I needed something faster and less specific.  That function
works and is brilliant but it scans the entire strings and checks that
it conforms to UTF-8



function detectUTF8($string)
{
return preg_match('%(?:
[\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
|\xE0[\xA0-\xBF][\x80-\xBF] # excluding

Hot in Week

Popular

Archive

item