APP NEWS
常见的 PHP 截取字符串函数整理
1、截取GB2312字符用的函数<?php//截取中文字符串function mysubstr($str,$start,$len) { $tmpstr=""; $strlen=$st

1、截取GB2312字符用的函数
//截取中文字符串
function mysubstr($str, $start, $len) {
$tmpstr = &&;
$strlen = $start + $len;
for($i = 0; $i < $strlen; $i++) {
if(ord(substr($str, $i, 1)) > 0xa0) {
$tmpstr .= substr($str, $i, 2);
$i++;
} else
$tmpstr .= substr($str, $i, 1);
}
return $tmpstr;
}
?>
2. 截取utf8编码的多字节字符串
//截取utf8字符串
function utf8Substr($str, $from, $len)
{
return preg_replace('#^(?:[x00-x7F]|[xC0-xFF][x80-xBF]+){0,'.$from.'}'.
'((?:[x00-x7F]|[xC0-xFF][x80-xBF]+){0,'.$len.'}).*#s',
'$1',$str);
}
?>
3. UTF-8、GB2312都支持的汉字截取函数
/*
Utf-8、gb2312都支持的汉字截取函数
cut_str(字符串, 截取长度, 开始长度, 编码);
编码默认为 utf-8
关键词标签:PHP,截取字符串函数
相关阅读 2021年最好用的10款php开发工具推荐 plsql developer怎么连接数据库-plsql developer连接数据库方法 php利用淘宝IP库获取用户ip地理位置 在 PHP 中使用命令行工具 php出现Cannot modify header information问题的解决方法大全 详解ucenter原理及第三方应用程序整合思路、方法
文章评论查看所有0条评论>>
发表评论提交评论
热门文章
2021年最好用的10款php开发工具推荐
plsql developer怎么连接数据库-plsql developer连接数据库方法
在 PHP 中使用命令行工具
php应用程序安全防范技术研究
关于php curl获取301或302转向的网址问题
人气排行 详解ucenter原理及第三方应用程序整合思路、方法 plsql developer怎么连接数据库-plsql developer连接数据库方法 PHP中防止SQL注入攻击 PHP会话Session的具体使用方法解析 PHP运行出现Notice : Use of undefined constant 的解决办法 PHP如何清空mySQL数据库 CakePHP程序员必须知道的21条技巧 PHP采集图片实例(PHP采集) 完美解决failed to open stream: HTTP request failed! phpinfo() ?>无法执行的解决办法 2021年最好用的10款php开发工具推荐 用header或meta实现PHP页面编码的区别
关于我们| 下载帮助| 版权声明| 合作伙伴| 友情连接| 联系我们| 网站地图Copyright © 2007-2026 IT猫扑网 All Rights Reserved. 豫ICP备2026021191号-1 豫公网安备42010145200009号
{ "@context": "https://zhanzhang.baidu.com/contexts/cambrian.jsonld", "@id": "https://www.itmop.com/article/4659.html", "appid": "否", "title": "常见的 PHP 截取字符串函数整理-IT猫扑网", "images": ["/e/data/images/notimg.gif"], "description": "{$Excerpt}", "pubDate": "2015-06-28T00:00:00", "upDate": "2015-06-28T00:00:00", "data": { "WebPage": { "pcUrl": "https://www.itmop.com/article/4659.html", "wapUrl": "https://m.itmop.com/article/4659.html", "fromSrc": "IT猫扑网" } } }





