小白教程
所有教程
关于
Search
172.71.255.12
172.71.255.12
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Func string explode”的源代码
本页内容
上一节:
Func_string_echo
下一节:
Func_string_fprintf
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:explode()}}[[分类:PHP字符串函数参考手册|14]] = PHP explode() 函数 = [[:分类:PHP字符串函数参考手册]] 把字符串打散为数组: <sample title="" desc="" lang="php" hererun="1"> <?php $str = "www.xiaobai.wang"; print_r (explode(".",$str)); ?> </sample> == 定义和用法 == explode() 函数使用一个字符串分割另一个字符串,并返回由字符串组成的数组。 '''注释:'''"separator" 参数不能是一个空字符串。 '''注释:'''该函数是二进制安全的。 == 语法 == explode(separator,string,limit) {| class="table table-striped table-hover" !width="50%"| 参数 !width="50%"| 描述 |- | separator | 必需。规定在哪里分割字符串。 |- | string | 必需。要分割的字符串。 |- | limit | 可选。规定所返回的数组元素的数目。 可能的值: * 大于 0 - 返回包含最多 limit 个元素的数组 * 小于 0 - 返回包含除了最后的 -limit 个元素以外的所有元素的数组 * 0 - 会被当做 1, 返回包含一个元素的数组 |} == 技术细节 == {| class="table table-striped table-hover" | 返回值: | 返回字符串数组。 |- | PHP 版本: | 4+ |- | 更新日志: | 在 PHP 4.0.1 中,新增了 limit 参数。在 PHP 5.1.0 中,新增了对负数 limits 的支持。 |} == 更多实例 == == 实例 1 == 使用 limit 参数来返回一些数组元素: <sample title="" desc="" lang="php" hererun="1"> <?php $str = 'one,two,three,four'; // 返回包含一个元素的数组 print_r(explode(',',$str,0)); print "<br>"; // 数组元素为 2 print_r(explode(',',$str,2)); print "<br>"; // 删除最后一个数组元素 print_r(explode(',',$str,-1)); ?> </sample> [[:分类:PHP字符串函数参考手册]]
返回至“
Func string explode
”。
上一节:
Func_string_echo
下一节:
Func_string_fprintf