Home > php教程 > php手册 > body text

php中explode函数用法分析,phpexplode函数用法

WBOY
Release: 2016-06-13 09:21:04
Original
1136 people have browsed it

php中explode函数用法分析,phpexplode函数用法

本文实例分析了php中explode函数用法。分享给大家供大家参考。具体如下:

explode(string separator,string string [,int limit])

separator 为空字符串(""),explode() 将返回 FALSE,如果 separator 所包含的值在 string 中找不到,那么 explode() 将返回包含 string 单个元素的数组.

explode实例一,代码如下:

复制代码 代码如下:

$explode = "aaa,bbb,ccc,ddd,explode,jjjj";
 
$array = explode( ',' ,$explode );
 
print_r($array);
/*
//结果为
Array
(
    [0] => aaa
    [1] => bbb
    [2] => ccc
    [3] => ddd
    [4] => explode
    [5] => jjjj
)
*/


我们在处理日期或取得文件扩展名时就可以用explode函数与end函数操作,下面来看实例,代码如下:

复制代码 代码如下:

$file ="www.jb51.net.gif";
 
 $extArray = explode( '.' ,$file );
 $ext = end($extArray);
 echo $ext;
 
//输出值为.gif


使用些函数出现的错误提示有:Note: Separator cannot be an empty string.注意:分割符不可以是空字符串,要分割的字符串为空.

Definition and Usage 未使用分割函数,可能是你设置的分割字符不存在.

希望本文所述对大家的PHP程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!