字符串函数 explode ()
使用一个字符串分割另一个字符串,把字符串打散为数组。 explode ()#
explode(string $separator, string $string, int $limit) : array
此函数返回字符串的数组,每个元素都是 string
的一个子串,它们被字符串 delimiter
作为边界点分割出来。
参数 | 描述 |
---|---|
separator | 必需。规定在哪里分割字符串。 |
string | 必需。要分割的字符串。 |
limit | 可选。规定所返回的数组元素的数目。 可能的值: 大于 0 - 返回包含最多 limit 个元素的数组 小于 0 - 返回包含除了最后的 -limit 个元素以外的所有元素的数组 0 - 返回包含一个元素的数组 |
$str = 'one,two,three,four';
// 零 limit
print_r(explode(',',$str,0));
// 正的 limit
print_r(explode(',',$str,2));
// 负的 limit
print_r(explode(',',$str,-1));
Array (
[0] => one,two,three,four
)
Array (
[0] => one [1] => two,three,four
)
Array (
[0] => one [1] => two [2] => three
)
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: