$array = split(':', "One:Two:Three');
The preceding code returns an array with three strings in it, namely One, Two, and Three. Regular expressions, however, let us be more flexible:
$array = split('[|:, ]', 'One|Two:Three Four,Five');
The first parameter in the preceding code says to use any of the characters as a valid separator, so we will see an array with five strings in it after executing this code:
Array (  => One  => Two  => Three  => Four  => Five )
If we have a very long string that represents a number of lines of text, each separated by a newline character, we can write the following code to split them up:
if (substr($_SERVER['OS'], 'Windows') !== FALSE) $nl = '\r\n'; else // Unix $nl = '\n'; $array = split($nl, $extremely_long_text);
$array variable now contains each of the lines in the
$exTRemely_long_text variable as individual values within the array (without any of the newline characters).
PHP includes another function that does something similar to
explode. This function is not multi-byte character safe, but it is significantly faster than
split. We will therefore use these functions interchangeably. We will use
explode when we are absolutely guaranteed that our input is in single-byte character sets such as ISO-8859-1, and
split when we are dealing with user input.