note 39932 deleted from function.utf8-encode by cmb

From: Date: Sun, 22 Dec 2019 08:59:21 +0000
Subject: note 39932 deleted from function.utf8-encode by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-213573@lists.php.net to get a copy of this message
Note Submitter: bmorel at ssi dot fr ---- Here is a simple function that can help, if you want to know if a string could be UTF-8 or not : <?php function seems_utf8($Str) { for ($i=0; $i<strlen($Str); $i++) { if (ord($Str[$i]) < 0x80) $n=0; # 0bbbbbbb elseif ((ord($Str[$i]) & 0xE0) == 0xC0) $n=1; # 110bbbbb elseif ((ord($Str[$i]) & 0xF0) == 0xE0) $n=2; # 1110bbbb elseif ((ord($Str[$i]) & 0xF0) == 0xF0) $n=3; # 1111bbbb else return false; # Does not match any model for ($j=0; $j<$n; $j++) { # n octets that match 10bbbbbb follow ? if ((++$i == strlen($Str)) || ((ord($Str[$i]) & 0xC0) != 0x80)) return false; } } return true; } ?>

« previous php.notes (#213573) next »