Usage of php explode function

怪我咯
Release: 2023-03-12 20:40:01
Original
2437 people have browsed it

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 
) 
*/
Copy after login

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 ="m.sbmmt.comt.gif"; 
 
 $extArray = explode( '.' ,$file ); 
 $ext = end($extArray); 
 echo $ext; 
 
//输出值为.gif
Copy after login

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!

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 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!