UTF8 string length counter
The best way to determine the character count of a UTF8 string.
function strlen_utf8( $str ) { return mb_strlen( $str, 'UTF-8' ); } //or... function strlen_utf8( $str ) { $c = 0; $len = strlen( $str ); for ( $i = 0; $i < $len; $i++ ) { //0x80 = 128 $ord = ord( $str[$i] ); if ( $ord & 0x80 ) { $ord <<= 1; while ( $ord & 0x80 ) { $i++; $ord <<= 1; } $c++; } else { $c++; } } return $c; }