Explode () function introduction
The explode () function splits a string into arrays.
Syntax: Explode (separator,string,limit).
- Separator, required. Specifies where to split the string.
- string, required. The string to split.
- Limit, optional. Specifies the maximum number of array elements that are returned.
This function returns an array of strings, each of which is a substring separated by separator as a boundary point.
The separator parameter cannot be an empty string. If separator is an empty string (""), Explode () returns FALSE. If separator contains a value that is not found in a string, explode () returns an array containing a single element in the string.
If the limit parameter is set, the returned array contains a maximum of limit elements, and the last element will contain the remainder of the string.
If the limit parameter is a negative number, all elements except the last-limit element are returned. This feature is new in PHP 5.1.0.
Program List:explode () example
Program Run Result:
applebananagonn*
Program List: Explode () example using the limit parameter
Program Run Result:
Array ([0] = one [1] = Two|three|four) Array ([0] = one [1] = [ 2] = three)
Program List: Converts a string into an array of key values
') { if ($a = explode ($delimiter, $string)) {//Create parts foreach ($a as $s) {//each part if ($s) { if ($pos = Strpos ($s, $kv)) {//Key/value delimiter $ka [Trim (substr ($s, 0, $pos))] = Trim (substr ($s, $pos + strlen ($k v))); } else {//key delimiter not found $ka [] = trim ($s);}} } return $ka; }} string2keyedarray$string = ' a=>1, b=>23, $a, c=>45%, True, D=>ab C ';p rint_r (String2keyedarray ($string));? >
Program Run Result:
Array ([A] = 1 [b] = [ 0] = = $a [c] = = 45% [1] = = True [d] = ab c)
http://www.bkjia.com/PHPjc/752388.html www.bkjia.com true http://www.bkjia.com/PHPjc/752388.html techarticle the Explode () function introduces the explode () function to divide a string into arrays. Syntax: Explode (separator,string,limit). Separator, required. Specifies where to split the string. String, ...