seems_utf8 [ WordPress Function ]
seems_utf8 ( $str )
| Parameters: |
|
| Returns: |
|
| Defined at: |
|
Checks to see if a string is utf8 encoded.
NOTE: This function checks for 5-Byte sequences, UTF8 has Bytes Sequences with a maximum length of 4.
Source
<?php
function seems_utf8($str) {
$length = strlen($str);
for ($i=0; $i < $length; $i++) {
$c = ord($str[$i]);
if ($c < 0x80) $n = 0; # 0bbbbbbb
elseif (($c & 0xE0) == 0xC0) $n=1; # 110bbbbb
elseif (($c & 0xF0) == 0xE0) $n=2; # 1110bbbb
elseif (($c & 0xF8) == 0xF0) $n=3; # 11110bbb
elseif (($c & 0xFC) == 0xF8) $n=4; # 111110bb
elseif (($c & 0xFE) == 0xFC) $n=5; # 1111110b
else return false; # Does not match any model
for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ?
if ((++$i == $length) || ((ord($str[$i]) & 0xC0) != 0x80))
return false;
}
}
return true;
}
?>
Examples [ wp-snippets.com ]
Google Arama Sonuçlarý
- Function Reference/seems utf8 « WordPress Codex
Description. Checks to see if a string is utf8 encoded. Usage. <?php seems_utf8( $str ); ?> Parameters. $str: (string) (required) The string to be checked. Default: ...
codex.wordpress.org - #9692 (seems_utf8() can be improved) – WordPress Trac
while working on a utf8 related issue I ran over some little improvements of the seems_utf8() function originally be bmorel at ssi dot fr. larger string can benefit ...
core.trac.wordpress.org - utf 8 - PHP input filtering - checking ascii vs checking utf8 - Stack ...
I did some benchmarking on 100 strings (half valid utf8/ascii and half not) and found that seems_utf8() tasks 0.011 while is_ascii only takes ...
stackoverflow.com - 常用函数-seems_utf8() | WordPress啦!
2009年5月11日 ... 常用函数-seems_utf8(). 说明. 检查是否有urf8编码格式的字符串。 用法. <?php seems_utf8( $Str ) ?> 参数. $Str. (字符串)(必需)被检查的字符串 ...
www.wordpress.la