The contents of an ordered split of PHP strings are important in PHP, and this article describes the operation of an ordered split of PHP strings.
Here are some of the functions
Chunk_split (): A function splits a string into a series of smaller parts.
Explode (): Splitting another string with one string
Str_split (): Splitting a string into an array
Chunk_split ()
Chunk_split (String,length,end)
Parameter description
string is required. Specifies the string to be split.
Length is optional. A numeric value that defines the length of the string block. The default is 76.
End is optional. A string value that defines what is placed at the end of each string block. The default is \ r \ n.
<!--? PHP$STR = "Shanghai"; Echo Chunk_split ($str, 1, ".");? -
Input result: S.h.a.n.g.h.a.i.
Explode ()
This function is an inverse of implode (), uses one string to split another string, and returns an array.
Array explode (string separator, string string [, int limit])
<!--? php$str = ' One|two|three|four ';p rint_r (Explode (' | ', $STR));p Rint_r (Explode (' | ', $STR, 2));//negative limit (from PHP 5.1) Print_r (Explode (' | ', $STR,-1));? -
The output results are as follows:
Array ( [0] = one [1] = [ 2] = = Three [3] = four) array ( [0] = = one [1] = t Wo|three|four) Array ( [0] = One [1] = [2] = three) Str_split () Str_split () splits the string into an array, An array was returned successfully. Array Str_split (string string [, int length])
Parameter description
String that needs to be split
Length optional, representing the lengths of each split unit, not less than 1
Example:
<!--? Php$str = ' One Three ', $arr 1 = str_split ($STR), $arr 2 = Str_split ($str, 3);p Rint_r ($arr 1);p Rint_r ($arr 2);? -
The output results are as follows:
Array ( [0] = = o [1] = n [2] = + E [3] = = [4] = [5] + W [6] = = O [ 7] = [8] = = [ 9] = h [ten] = R [one] ~ ~ E [A] + e) Array ( [0] = one
[1] = tw [2] = = O T [3] = HRE [4] = = e)
This article explains the sequential splitting of PHP strings related operations, more relevant content please focus on PHP Chinese web.