<?
// ### 切分字符串 ####
function jb51netcut($start,$end,$file){
$content=explode($start,$file);
$content=explode($end,$content[1]);
return $content[0];
}
?>
| 参数 | 描述 |
|---|---|
| separator | 必需。规定在哪里分割字符串。 |
| string | 必需。要分割的字符串。 |
| limit | 可选。规定所返回的数组元素的最大数目。 |
<?php
$str = "Hello world. It's a beautiful day.";
print_r (explode(" ",$str));
?>
语法:
array str_split( string string [, int length] )
| 参数 | 说明 |
|---|---|
| string | 需要分割的字符串 |
| length | 可选,表示每个分割单位的长度,不可小于1 |
例子:
<?php
$str = 'one two three';
$arr1 = str_split($str);
$arr2 = str_split($str, 3);
print_r($arr1);
print_r($arr2);
?>
输出结果如下:
Array
(
[0] => o
[1] => n
[2] => e
[3] =>
[4] => t
[5] => w
[6] => o
[7] =>
[8] => t
[9] => h
[10] => r
[11] => e
[12] => e
)
Array
(
[0] => one
[1] => tw
[2] => o t
[3] => hre
[4] => e
)
$test = end(explode('.', 'abc.txt'));
echo $test;//output txt
$test1 = end(split('.','abc.txt'));
echo $test1;//no output
$test1 = end(split('\.','abc.txt'));
echo $test1;//output txt
<?php
$zongzi = "1|2|3|4|5|6";
$zongzi = explode("|",$zongzi);
var_dump($zongzi);
$zongzi = implode("|",$zongzi);
echo $zongzi;
?>
如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛