PHP explode() 函數
定義和用法
explode() 函數把字符串打散為數組。
注釋:"separator" 參數不能是空字符串。
注釋:該函數是二進制安全的。
語法
explode(separator,string,limit)
參數 | 描述 |
---|---|
separator | 必需。規定在哪里分割字符串。 |
string | 必需。要分割的字符串。 |
limit |
可選。規定所返回的數組元素的數目。 可能的值:
|
技術細節
返回值: | 返回字符串的數組 |
PHP 版本: | 4+ |
更新日志: | 在 PHP 4.0.1 中,新增了 limit 參數。在 PHP 5.1.0 中,新增了對負數 limit 的支持。 |
更多實例
例子 1
使用 limit 參數來返回一些數組元素:
<?php $str = 'one,two,three,four'; // 零 limit print_r(explode(',',$str,0)); // 正的 limit print_r(explode(',',$str,2)); // 負的 limit print_r(explode(',',$str,-1)); ?>