php指定长度分割字符串str_split函数用法示例
作者:design321 时间:2023-07-08 23:25:51
本文实例讲述了php指定长度分割字符串str_split函数用法。分享给大家供大家参考,具体如下:
示例1:
$str = 'abcdefgh';
$arr = str_split($str,2);
运行结果如下:
array(4) {
[0]=>
string(2) "ab"
[1]=>
string(2) "cd"
[2]=>
string(2) "ef"
[3]=>
string(2) "gh"
}
示例2:
$str = 'abcdefgh';
$arr = str_split($str);
$i = 0;
$limit = 3;
$num = count($arr);
while($i <= $num-1){
$temp = array();
$for_countbu = ($num-$i) >= $limit ? $limit : $num - $i;
for($j = 0; $j < $for_countbu; ++$j)
{
$temp[] = $arr[$i];
++$i;
}
$one = implode('',$temp);
$result[] = $one;
}
print_r($result);
运行结果如下:
array(4) {
[0]=>
string(2) "ab"
[1]=>
string(2) "cd"
[2]=>
string(2) "ef"
[3]=>
string(2) "gh"
}
希望本文所述对大家PHP程序设计有所帮助。
标签:php,str,split,函数
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python实现模拟时钟代码推荐
2023-08-03 05:26:09
简单了解什么是神经网络
2023-10-11 22:26:34
![](https://img.aspxhome.com/file/2023/8/89318_0s.png)
使用Python自动生成HTML的方法示例
2022-08-12 12:12:18
python使用epoll实现服务端的方法
2021-05-16 22:52:34
sql ntext数据类型字符替换实现代码
2011-09-30 11:08:00
微信小程序实现触底加载
2024-04-23 09:30:21
![](https://img.aspxhome.com/file/2023/8/135488_0s.jpg)
python实现多人聊天室
2022-09-02 18:56:21
python使用requests.session模拟登录
2022-09-12 19:17:24
![](https://img.aspxhome.com/file/2023/1/95301_0s.png)
MySQL事务处理与应用简析
2024-01-21 09:01:24
Python入门教程(一)Python简单介绍
2023-10-25 03:19:16
Python使用多进程运行含有任意个参数的函数
2023-10-14 23:22:12
![](https://img.aspxhome.com/file/2023/1/123831_0s.jpg)
GO CountMinSketch计数器(布隆过滤器思想的近似计数器)
2024-02-17 06:12:40
![](https://img.aspxhome.com/file/2023/3/108093_0s.png)
javascript将中国数字格式转换成欧式数字格式的简单实例
2024-05-09 10:20:21
编写安全的SQL Server扩展存储过程
2008-11-25 11:16:00
python argparse传入布尔参数false不生效的解决
2023-07-03 16:12:20
Python数据类型详解(二)列表
2021-10-26 08:47:11
node.js应用后台守护进程管理器Forever安装和使用实例
2024-05-03 15:36:48
pytorch中torch.topk()函数的快速理解
2023-09-07 10:21:52
![](https://img.aspxhome.com/file/2023/6/114496_0s.png)
go语言csrf库使用实现原理示例解析
2023-08-07 03:34:38
![](https://img.aspxhome.com/file/2023/7/97167_0s.jpg)
谈切图优化加速图片显示—淘宝实例
2008-01-30 12:24:00
![](https://img.aspxhome.com/file/UploadPic/20081/30/200813012349773s.gif)