php开源嘛
首页 | English | MySql数据库 | Php编程 | 建站杂烩 | 系统服务器 | 资源共享 | 专题 | 才桀网 | 支持论坛
  当前位置:主页>English>文章内容
php表达式之explode() 分割字符串
来源:php手册 作者:本站整理 发布时间:2007-12-15  

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

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  = "piece1 piece2 piece3 piece4 piece5 piece6"
;
$pieces = explode(" ", $pizza
);
echo
$pieces[0];
// piece1
echo $pieces[1];
// piece2

// 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 examplesphpma.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] => two
    [2] => three
)

注: 该函数适用于二进制对象!phpma.com


(阅读次数:
上一篇:经营博客的十个秘决:作者-李黑   下一篇:MySQL数据库中与NULL值有关的问题集
[收藏] [推荐] [评论(0条)] [返回顶部] [打印本页] [关闭窗口]  
用户名: 新注册) 密码: 匿名评论
评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
 §最新评论
  热点文章
·什么是Smaty?一个php模板引擎.
·Mysql中innodb 和myisam的区别?
·what is apache? 服务器
·What is PHP?
·Apache是一款流行的伺服器
·what is openssh?而ssh又是什么?
·What is MySQL? MySQL数据库
·what is Linux? 操作系统
·php|works, Session Day 1
·Late static binding....sorta .
·What is EditPlus?How to Instal
·Ajax技术(五)用AjaxTags简化Ajax
  相关文章
·Ajax技术(一)用AjaxTags简化Ajax
·what is openssh?而ssh又是什么?
·Ajax技术(二)用AjaxTags简化Ajax
·Ajax技术(三)用AjaxTags简化Ajax
·Ajax技术(四)用AjaxTags简化Ajax
·Ajax技术(五)用AjaxTags简化Ajax
·Ajax 能够做什么?
·PHP&Smarty Is Smarty right for
·Smarty:Why use it?模板怎么使
·Mysql中innodb 和myisam的区别?
·What is EditPlus?How to Instal
·Late static binding....sorta .

关于我们 | 本站声明 | 友情连接 | 诚邀加盟 | 网站地图
版权Power by DedeCms   技术支持QQ =>> 罗江游鱼   Jacking  后台登陆
Copyright @ 2007 公司地址:柳州市东环路268号 邮编:545006 电话:15920389818 桂ICP备07006725号