易截截图软件、单文件、免安装、纯绿色、仅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实现”服务器推”技术的聊天室

    * 作者: laruence(http://www.laruence.com)
    * 本文地址: http://www.laruence.com/2008/04/16/118.html
    * 转载请注明出处
传统的B/S结构的应用程序,都是采用”客户端拉”结束来实现客户端和服务器端的数据交换。
本文将通过结合Ticks(可以参看我 ......

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

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

PHP配置MYSQL

这两天在捣鼓PHP,去ecshop和phpwind下载了一个商城和一个论坛。两个都需要安装mysql的服务器,于是我按照教程进行安装。结果发现每次都是到连接数据库的地方就变成空白页了。死活找不出来问题。后来在余建的指导下,发现原来是PHP的版本过高。真是郁闷。
现在我把我最近配置的过程写出来。
所需软件:
apache_2.2.14-wi ......

php 模式修正符

模式修正符 — 解说正则表达式模式中使用的修正符
说明
下面列出了当前在 PCRE 中可能使用的修正符。括号中是这些修正符的内部 PCRE 名。修正符中的空格和换行被忽略,其它字符会导致错误。
 
i (PCRE_CASELESS) 如果设定此修正符,模式中的字符将同时匹配大小写字母。 m(PCRE_MULTILINE) 默认情况下,PCR ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号