Php/func string explode
来自菜鸟教程
PHP explode()函数
例
将字符串分成数组:
<?php
$str = "Hello world. It's a beautiful day.";
print_r (explode(" ",$str));
?>
定义和用法
explode()函数将字符串分成数组。
注意: “ separator”参数不能为空字符串。
注意: 此函数是二进制安全的。
句法
explode(separator,string,limit)
参数值
| 参数 | 描述 |
|---|---|
| separator | 需要。指定在何处断开字符串 |
| string | 需要。要分割的字符串 |
| limit |
可选的。指定要返回的数组元素的数量。 可能的值:
|
技术细节
| 返回值: | 返回字符串数组 |
| PHP版本: | 4+ |
| 更新日志: | The
limit 参数已在PHP 4.0.1中添加,并支持负数 limits 在PHP 5.1.0中添加 |
更多例子
例
使用limit参数返回多个数组元素:
<?php
$str = 'one,two,three,four';
// zero limit
print_r(explode(',',$str,0));
// positive limit
print_r(explode(',',$str,2));
// negative limit
print_r(explode(',',$str,-1));
?>