易截截图软件、单文件、免安装、纯绿色、仅160KB

php表达式之explode() 分割字符串

原帖地址:http://www.phpma.com/english/20071215/640.html
Description
array explode
( string separator, string string [, int limit])phpma.com
Returns an array of strings, each of which is a substring of string
formed by splitting it on boundaries formed by the string separator
. If limit
is set, the returned array will contain a maximum of limit
elements with the last element containing the rest of string
.
If separator
is an empty string (""), explode()
will return FALSE
. If separator
contains a value that is not contained in string
, then explode()
will return an array containing string
.
If the limit
parameter is negative, all components except the last limit
are returned. This feature was added in PHP
5.1.0
.
Although implode()
can, for historical reasons, accept its parameters in either order, explode()
cannot. You must ensure that the separator
argument comes before the string
argument.
注:
The limit
parameter was added in PHP
4.0.1

phpma.com
例子
1
.
explode()
examples
<?php
// Example
1
$pizza 
=
"piece
1
piece
2
piece
3
piece
4
piece
5
piece
6
"
;
$pieces
=
explode
(
" "
,
$pizza
);
echo
$pieces
[
0
];
// piece
1
echo
$pieces
[
1
];
// piece
2
// Example
2
$data
=
"foo:*:
1023
:
1000
::/home/foo:/bin/sh"
;
list(
$user
,
$pass
,
$uid
,
$gid
,
$gecos
,
$home
,
$shell
) =
explode
(
":"
,
$data
);
echo
$user
;
// foo
echo
$pass
;
// *
?>

例子
2
.
limit
parameter examples
phpma.com
<?php
$str
=
'one|two|three|four'
;
// positive limit
print_r
(
explode
(
'|'
,
$str
,
2
));
// negative limit
print_r
(
explode
(
'|'
,
$str
, -
1
));
?>

The above example will output:
Array
(
[
0
] => one
[
1
] => two|three|four
)
Array
(
[
0
] => one
[
1


相关文档:

【PHP系列教程】(4)——PHP的变量

很荣幸上篇文章被版主推荐到首页了,心里算是激动了一把,继续努力学习中吧。本章主要介绍PHP中的变量。主要包括:预定义变量、变量范围、可变变量以及PHP的外部变量等。
一、基础知识
PHP 中一个美元符号后面跟上一个变量名称,即表示一个变量。变量的名称是对大小写敏感的。
变量名与 PHP 中其它的标签一样遵循相同的 ......

PHP 中巧用数组降低程序的时间复杂度

通常开发人员在写程序的时候,往往是把已经设计好或者构思好的运算逻辑,直接用编程语言翻译出来。程序能顺利编译通过,那是很令人高兴的事情。如果此时程序的运行时间还能接受,就会沉浸在写代码的成就感当中,常常在这个过程中忽略代码的优化。只有当程序运行速度受到影响时,才回过头去考虑优化的事情。
什么是算法的时 ......

PHP中getenv()函数

getenv()   取得系统的环境变量(预定义变量)
$spager=getenv('SERVER_NAME');
“PHP_SELF”
当前正在执行脚本的文件名,与 document root 相关。举例来说,在 URL 地址为 [url]http://example.com/test.php/foo.bar[/url] 的脚本中使用 $_SERVER['PHP_SELF'] 将会得到 /test.php/foo.bar 这个结 ......

PHP获取IP地址的多种有效方法

<?php
echo "<br>";
?>
<?php
  
function GetIP()
{
if(!empty($_SERVER["HTTP_CLIENT_IP"]))
   $cip = $_SERVER["HTTP_CLIENT_IP"];
else if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"]))
   $cip = $_SERVER["HTTP_X_FORWARDED_FOR"];
else if(!empty($_SERVER ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号