Usage Analysis of explode Function in php

  • 2021-07-26 07:18:51
  • OfStack

In this paper, the usage of explode function in php is analyzed with examples. Share it for your reference. The details are as follows:

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

separator is an empty string (""), explode () returns FALSE, and explode () returns an array containing individual elements of string if separator contains a value not found in string.

explode instance 1, with the following code:

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

We can use explode function and end function when dealing with dates or getting file extensions. Let's look at the example below. The code is as follows:
$file ="www.ofstack.com.gif"; 
 
 $extArray = explode( '.' ,$file );
 $ext = end($extArray);
 echo $ext;
 
// The output value is .gif

Errors when using some functions are: Note: Separator cannot be an empty string. Note: The divider cannot be an empty string, the string to be divided is empty.

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

I hope this article is helpful to everyone's PHP programming.


Related articles: