Home  >  Article  >  Backend Development  >  Usage of php explode function

Usage of php explode function

怪我咯
怪我咯Original
2017-07-06 10:24:482460browse

This article mainly introduces the usage of explode function in php. It analyzes the applications of explode function to split string and obtain file suffix name with examples. It has certain reference value. Friends who need it can refer to

. This article analyzes the usage of the explode function in PHP with examples. Share it with everyone for your reference. The details are as follows:

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

separator is an empty string (""), explode() will return FALSE , if the value contained in separator is not found in string, then explode() will return an array containing a single element of string.

explode instance one, the code is as follows:

The code is as follows:

$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 
) 
*/

When we process dates or obtain file extensions, we can use the explode function and end function to operate. Let’s look at the example below. The code is as follows:

The code is as follows:

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

The error messages that appear when using some functions are: Note: Separator cannot be an empty string. Note: The separator cannot be an empty string, and the string to be split is empty.

Definition and Usage The split function is not used. It may be that the split character you set does not exist.

The above is the detailed content of Usage of php explode function. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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