您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php explode函数怎么用?

2025/10/15 5:51:57发布11次查看
php explode函数用于把字符串打散为数组,其语法是explode(separator,string,limit),参数separator必需,规定在哪里分割字符串;string必需,指要分割的字符串。
php explode函数怎么用?
定义和用法
explode() 函数把字符串打散为数组。
注释:separator 参数不能是空字符串。
注释:该函数是二进制安全的。
语法
explode(separator,string,limit)
参数
separator 必需。规定在哪里分割字符串。
string 必需。要分割的字符串。
limit 可选。规定所返回的数组元素的数目。
可能的值:
大于 0 - 返回包含最多 limit 个元素的数组
小于 0 - 返回包含除了最后的 -limit 个元素以外的所有元素的数组
0 - 返回包含一个元素的数组
返回值: 返回字符串的数组
php 版本: 4+
更新日志:
在 php 4.0.1 中,新增了 limit 参数。在 php 5.1.0 中,新增了对负数 limit 的支持。
例子 1
使用 limit 参数来返回一些数组元素:
<?php$str = 'one,two,three,four';// 零 limitprint_r(explode(',',$str,0));// 正的 limitprint_r(explode(',',$str,2));// 负的 limitprint_r(explode(',',$str,-1));?>
输出:
array ( [0] => one,two,three,four ) array ( [0] => one [1] => two,three,four ) array ( [0] => one [1] => two [2] => three )
实例 2
把字符串打散为数组:
<?php$str = "hello world. i love shanghai!";print_r (explode(" ",$str));?>
输出:
array ( [0] => hello [1] => world. [2] => i [3] => love [4] => shanghai! )
以上就是php explode函数怎么用?的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product