博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
php多语言截取字符串函数
阅读量:6903 次
发布时间:2019-06-27

本文共 1041 字,大约阅读时间需要 3 分钟。

|\r|\n|\s|\[.+?\])/is", ' ', $str); if (function_exists("mb_substr")) $slice = mb_substr($str, $start, $length, $charset); elseif (function_exists('iconv_substr')) { $slice = iconv_substr($str, $start, $length, $charset); if (false === $slice) { $slice = ''; } } else { $re['utf-8'] = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/"; $re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/"; $re['gbk'] = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/"; $re['big5'] = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/"; preg_match_all($re[$charset], $str, $match); $slice = join("", array_slice($match[0], $start, $length)); } $fix = ''; if (LANG_SET == 'zh') { $slice = str_replace(' ', '', $slice); if (strlen($slice) > $length) { $fix = '...'; } } else { if (strlen($str) > $lenth2) { $fix = '...'; } } return $suffix ? $slice . $fix : $slice; }$str = "dsd个法师dsad打发dd的撒ddsddsadsadsads的撒";echo msubstr($str,1,2,20,true);?>

 

转载地址:http://heldl.baihongyu.com/

你可能感兴趣的文章
【Android】Retrofit 2.0 的使用
查看>>
Java程序员幽默爆笑锦集
查看>>
工作中常用到的ES6语法
查看>>
SAPGUI系统登录页面配置的SAProuter有什么用
查看>>
小程序hover-class点击态效果——小程序体验
查看>>
安装chrome插件
查看>>
Vue 中 CSS 动画原理
查看>>
Vue 中给组件绑定原生事件
查看>>
深入学习js之——执行上下文栈
查看>>
边缘计算入门指南
查看>>
华为云携手秒拍,云+AI助力短视频加速发展
查看>>
Vue CLI3.0 中使用jQuery 和 Bootstrap
查看>>
this 改变this的指向
查看>>
测试格式
查看>>
2-基础语法
查看>>
LeetCode1.两数之和JavaScript
查看>>
亲历者说:Kubernetes API 与 Operator,不为人知的开发者战争
查看>>
Hadoop小文件解决方案-基于NameNode内存和MapReduce性能解决方案
查看>>
gcc版本升级
查看>>
个人愚见: React 和 Vue 区别
查看>>