PHP explode() 函数
实例
把字符串打散为数组:
<?php
$str = "Hello world. It's a beautiful day.";
print_r (explode(" ",$str));
?>
亲自试一试 »
$str = "Hello world. It's a beautiful day.";
print_r (explode(" ",$str));
?>
定义和用法
explode() 函数把字符串打散为数组。
注释:"separator" 参数不能是空字符串。
注释:该函数是二进制安全的。
语法
explode(separator,string,limit)
参数值
| 参数 | 描述 | 
|---|---|
| separator | 必需。规定在哪里分割字符串。 | 
| string | 必需。要分割的字符串。 | 
| limit | 
 可选。规定所返回的数组元素的数目。 可能的值: 
  | 
技术细节
| 返回值: | 返回字符串的数组 | 
| PHP 版本: | 4+ | 
| 更新日志: | 在 PHP 4.0.1 中,新增了 limit 参数。在 PHP 5.1.0 中,新增了对负数 limit 的支持。 | 
更多实例
实例
使用 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));
?>
亲自试一试 »
$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));
?>
