Separating the strings, using "Str_split", the advantage is that even spaces are the elements of the array. My previous example is because the previous string contains 2 spaces, and the second one is only one. But the output will see the same display. You can also split by other separators, such as "explode" or "preg_split",
Separating the strings, using "Str_split", the advantage is that even spaces are the elements of the array. My previous example is because the previous string contains 2 spaces, and the second one is only one. But the output will see the same display.
You can also split by other separators, such as "explode" or "preg_split",
PHP tutorial Explode () function
PHP string function
Definition and usage
The explode () function splits the string into arrays.
Grammar
Explode (separator,string,limit) parameter description
Separator required. Specifies where to split the string.
string is required. The string to split.
Limit is optional. Specifies the maximum number of array elements that are returned.
Example
In this example, we will split the string into arrays:
$str = "Hello World". It ' s a beautiful day. ";
Print_r (Explode ("", $str));
?>
Output:
Array
(
[0] = = Hello
[1] = world.
[2] + = It ' s
[3] = a
[4] = Beautiful
[5] = = Day.
)
Str_split Split function
Definition and usage
The Str_split () function splits a string into an array.
Grammar
Str_split (string,length) parameter description
string is required. Specifies the string to be split.
Length is optional. Specifies the length of each array element. The default is 1.
Description
If the length is less than 1,str_split () the function returns FALSE.
If length is longer than the string, the entire string is returned as the unique element of the array.
Example
Example 1
Print_r (str_split ("Hello"));
?>
Output:
Array
(
[0] = h
[1] = = E
[2] = l
[3] = L
[4] = O
)
Example 2
Print_r (str_split ("Hello", 3));
?>
Output:
Array
(
[0] = Hel
[1]
Preg_split--splitting a string with regular expressions
Description
Array Preg_split (string pattern, string subject [, int limit [, int flags]])
Returns an array that contains the substrings in the subject that are split along the boundary that matches the pattern.
If limit is specified, it returns up to the limit substring, and if limit is-1, it means there is no limit and can be used to continue to specify the optional parameter, flags.
Flags can be any combination of the following tags (with bitwise OR operator | Combination):
Preg_split_no_empty
If this tag is set, Preg_split () returns only non-empty components.
http://www.bkjia.com/PHPjc/445406.html www.bkjia.com true http://www.bkjia.com/PHPjc/445406.html techarticle separating strings, using Str_split, the advantage is that even spaces are the elements of an array. My previous example is because the previous string contains 2 spaces, and the second one is only one ...