PHP utf-8中文截取无乱码(字符串判断版本)
来源:互联网 发布:pc装mac os 编辑:程序博客网 时间:2024/05/18 14:46
/*E4 B8 AD E5 9B BD 中国1110 0100 10111000 101011011110 0101 100110111011110161 a0011 11010xxx xxxx ,1个字节110xx xxxx , 2个字节1110 xxxx, 31111 0xxxx 4...*/<pre name="code" class="php">$str = '中华人aaa民共b和国,c万岁';function utf8sub($str,$len){if($len <=0) return '';$length = strlen($str);$offset=0;$chars=0;$res='';while($chars<$len && $offset<$length){$heigh = decbin(ord(substr($str, $offset,1)));echo $heigh ,'</br>';if(strlen($heigh)<8){$count=1;}else if(substr($heigh,0,3) == '110'){$count=2;}else if(substr($heigh,0,4) == '1110'){$count=3;}else if(substr($heigh,0,5) == '11110'){$count=4;}else if(substr($heigh,0,6) == '111110'){$count=5;}else if(substr($heigh,0,7) == '1111110'){$count=6;}$res .= substr($str, $offset,$count);$chars += 1;$offset += $count;}return $res;}echo utf8sub($str,10);
0 0
- PHP utf-8中文截取无乱码(字符串判断版本)
- php utf-8字符集下实现中文无乱码截取
- 中文UTF-8截取无乱码 算法
- PHP无乱码截取中文字符串
- utf-8汉字字符串截取无乱码
- PHP中截取UTF-8中文字符串
- 没事写了两个函数,php中gbk和utf-8中文无乱码截取
- PHP 中文字符串截取函数(UTF-8)有效
- PHP字符串截取(无乱码)
- php截取中文无乱码
- PHP截取中文无乱码
- php中文截取无乱码
- PHP 中文无乱码截取
- mrytsr PHP截取中文字符串,无乱码,基于正则
- PHP字符串截取,无乱码
- php 中文字符串截取乱码
- php截取中文字符串无乱码的函数(主函数:ord()、substr())
- PHP 中文字符串截取无乱码的方法以及php汉字截取函数_preg_split()
- newInstance()和new()
- 高仿微信对话列表滑动删除效果
- css隐藏多余文字
- Windows 10 锁屏壁纸
- Android图片处理(Matrix,ColorMatrix)
- PHP utf-8中文截取无乱码(字符串判断版本)
- linux命令快速查询
- eclipse内存泄漏
- autorun.inf(自动运行文件)
- YT14——先来练练手(3)
- 细谈Highcharts(一)
- db2 端口号查询与修改
- 暂时刷完leetcode的一点小体会
- leetcode 5 最长回文串