woshinidefaner / note

tools
0 stars 0 forks source link

PHP 中文字符处理 utf-8 GBK #12

Open woshinidefaner opened 4 years ago

woshinidefaner commented 4 years ago

iconv("utf8","gbk",$string)//将字符串string 编码由utf8转变成gbk; iconv('GB2312', 'UTF-8', $str); //将字符串的编码从GB2312转到UTF-8;

mb_substr( $str, $start, $length, $encoding ); $str,需要截断的字符串; $start,截断开始处; $length,长度(注意,这个跟mb_strimwidth不同,1就代表一个中文字符); $encoding,编码,utf-8;GBK;

mb_strlen($str,$encoding);对于字符串,编码;

mb_convert_encoding( $str, $encoding1,$encoding2 ); $str,要转换编码的字符串; $encoding1,目标编码,如utf-8,gbk,大小写均可; $encoding2,原编码,如utf-8,gbk,大小写均可;