The syntax for the split function in PHP is: Array split (String $pattern, string $string [, int $limit])
The split () function returns an array of strings, each of which is a substring separated by a regular expression $pattern as a boundary $string. If $limit is set, the returned array contains up to $limit cells, and the last cell contains all the remaining parts of the $string.
Pattern: Specifies the symbol to be identified as an explosion, note that the parameter is case-sensitive.
$string: The string to be processed.
Limit: Returns the maximum number of decomposed substrings, which are returned by default.
Example
#1 Split () example
Put a string such as: "1:0:1:0:1″ into an array and then output
$str = "1:0:1:0:1″;
$arraylist =split (":", $STR); Save in Array
for ($i =0; $i <count ($arraylist); $i + +)//output them all
{
echo $arraylist [$i]. "";
}
#2 Split () example
To split off the ' the ' the ' four fields from line from/etc/passwd:
Divide the/ect/password into five parts: the first four and the last
<?php
List ($user, $pass, $uid, $gid, $extra) =
Split (":", $passwd _line, 5);
?>
#3 Split () example
To parse a date which may is delimited with slashes, dots, or hyphens:
To separate the date with a diagonal stem, dot, or horizontal line
<?php
Delimiters may be slash, dot, or hyphen
$date = "04/30/1973";
List ($month, $day, $year) = Split (' [/.-] ', $date);
echo "Month: $month; Day: $day; Year: $year <br/>\n ";
?>