Home >Backend Development >PHP Tutorial >php婚配utf-8完整字符,可以防止截取乱码

php婚配utf-8完整字符,可以防止截取乱码

WBOY
WBOYOriginal
2016-06-13 10:49:49783browse

php匹配utf-8完整字符,可以防止截取乱码

function utf8( $a, $s = '' ){	preg_match_all( '/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/', $a, $d, PREG_PATTERN_ORDER );	return join( $s, $d[0] );}

调用方式
utf8( substr( '截取我', 0, 5 ) );

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn