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

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

WBOY
Release: 2016-06-13 13:11:57
Original
849 people have browsed it

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] );
}
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template