Revision: 53286
Updated Code
at November 18, 2011 02:24 by n19ht
Updated Code
function isUTF8($string){ for($idx = 0, $strlen = strlen($string); $idx < $strlen; $idx++){ $byte = ord($string[$idx]); if($byte & 0x80){ if(($byte & 0xE0) == 0xC0){ // 2 byte char $bytes_remaining = 1; }elseif(($byte & 0xF0) == 0xE0){ // 3 byte char $bytes_remaining = 2; }elseif(($byte & 0xF8) == 0xF0){ // 4 byte char $bytes_remaining = 3; }else{ return false; } if($idx + $bytes_remaining >= $strlen){ return false; } while($bytes_remaining--){ if((ord($string[++$idx]) & 0xC0) != 0x80){ return false; } } } } return true; }
Revision: 53285
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at November 18, 2011 02:22 by n19ht
Initial Code
function isUTF8($string) { for ($idx = 0, $strlen = strlen($string); $idx < $strlen; $idx++) { $byte = ord($string[$idx]); if ($byte & 0x80) { if (($byte & 0xE0) == 0xC0) { // 2 byte char $bytes_remaining = 1; } else if (($byte & 0xF0) == 0xE0) { // 3 byte char $bytes_remaining = 2; } else if (($byte & 0xF8) == 0xF0) { // 4 byte char $bytes_remaining = 3; } else { return false; } if ($idx + $bytes_remaining >= $strlen) { return false; } while ($bytes_remaining--) { if ((ord($string[++$idx]) & 0xC0) != 0x80) { return false; } } } } return true; }
Initial URL
Initial Description
Esta función devuelve true si el argumento está codificado en utf8
Initial Title
Detectar Texto UTF8 en PHP
Initial Tags
php
Initial Language
PHP