seems_utf8()检测字符串是否是UTF-8编码

目录

描述

译文

检查是否有utf8编码格式的字符串。

原文

 字符 是否是 UTF-8 编码。

seems_utf8() 描述

用法

<?php seems_utf8$str ); ?>

seems_utf8() 用法

参数

$str

(string) (必填)  检测的字符串

默认值: None

seems_utf8() 参数

返回值

(boolean) 

  $str 是 UTF-8  码,返  true,否则返回 false。

seems_utf8() 返回值

历史

添加于 版本: 1.2.1

seems_utf8() 历史

源文件

seems_utf8() 函数的代码位于 wp-includes/formatting.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * 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.
 *
 * @author bmorel at ssi dot fr (modified)
 * @since 1.2.1
 *
 * @param string $str The string to be checked
 * @return bool True if $str fits a UTF-8 model, false otherwise.
 */
function seems_utf8( $str ) {
	mbstring_binary_safe_encoding();
	$length = strlen($str);
	reset_mbstring_encoding();
	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;"><$n; $j++)="" {="" n="" bytes="" matching="" 10bbbbbb="" follow="" if="" ((++$i="=" $length)="" ||="" ((ord($str[$i])="" &="" 0xc0)="" !="0x80))" return="" false;="" }="" }="" return="" true;="" }="">

seems_utf8() 源文件