php实现中文字串截取无乱码的方法
2017-08-21 10:20
666 查看
<?php
//实现中文字串截取无乱码的方法
header('Content-Type:text/html ; charset = utf8');
//自定义函数求长度
function strlen_utf8($str){
return count(preg_split('//u' , $str , -1 ,PREG_SPLIT_NO_EMPTY));
}
//自定义函数截取字符串
function substr_utf8($str ,$start ,$length=null){
return join("",array_slice(preg_split("//u", $str ,-1 ,PREG_SPLIT_NO_EMPTY), $start , $length));
}
$a = '中国2北333京';
echo strlen_utf8($a);
echo substr_utf8($a , 3 , 1);
//实现中文字串截取无乱码的方法
header('Content-Type:text/html ; charset = utf8');
//自定义函数求长度
function strlen_utf8($str){
return count(preg_split('//u' , $str , -1 ,PREG_SPLIT_NO_EMPTY));
}
//自定义函数截取字符串
function substr_utf8($str ,$start ,$length=null){
return join("",array_slice(preg_split("//u", $str ,-1 ,PREG_SPLIT_NO_EMPTY), $start , $length));
}
$a = '中国2北333京';
echo strlen_utf8($a);
echo substr_utf8($a , 3 , 1);
相关文章推荐
- PHP实现中文字串截取无乱码的方法…
- php实现中文字串截取无乱码的三种方法(详)
- PHP实现中文字串截取无乱码的方法
- 实现中文字串截取无乱码的方法php
- PHP中实现中文字串截取无乱码的解决方法
- php 实现中文字串截取无乱码的方法
- PHP实现中文字串截取无乱码的方法
- php实现中文字符截取防乱码方法汇总
- 【技术宅1】实现中文字串截取无乱码的方法
- 实现中文字串截取无乱码的方法
- PHP实现中文字串截取无乱码
- 实现中文字串截取无乱码的方法
- php中文字串截取乱码的解决方法
- php实现中文字符截取防乱码方法汇总
- PHP 实现中文截取无乱码的方法
- PHP技术分享--实现中文字串截取无乱码的函数(适用于utf-8)
- 实现中文字串截取无乱码的方法
- 用PHP来截取中文字符串而不出现乱码的实现方法
- PHP开发小技巧⑩—实现中文字符串截取无乱码的方法
- 实现中文字串截取无乱码的方法