检测字符串是否为UTF8编码
Jun 07, 2016 am 11:45 AM/**<br>
* 检测字符串是否为UTF8编码<br>
* @param string $str 被检测的字符串<br>
* @return boolean <br>
*/<br>
function is_utf8($str){<br>
$len = strlen($str); <br>
for($i = 0; $i
$c = ord($str[$i]); <br>
if ($c > 128) { <br>
if (($c > 247)) return false; <br>
elseif ($c > 239) $bytes = 4; <br>
elseif ($c > 223) $bytes = 3; <br>
elseif ($c > 191) $bytes = 2; <br>
else return false; <br>
if (($i + $bytes) > $len) return false; <br>
while ($bytes > 1) { <br>
$i++; <br>
$b = ord($str[$i]); <br>
if ($b 191) return false; <br>
$bytes--; <br>
} <br>
} <br>
} <br>
return true;<br>
}
AD:真正免费,域名+虚机+企业邮箱=0元

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Learn about introductory code examples for Python programming

PHP variables in action: 10 real-life examples of use

How to use PHP to write inventory management function code in the inventory management system

From beginner to proficient: Code implementation of commonly used data structures in Go language

Java implements simple bubble sort code

Go language programming examples: code examples in web development

Huawei Cloud Edge Computing Interconnection Guide: Java code examples to quickly implement interfaces

Guidance and Examples: Learn to implement the selection sort algorithm in Java
