PHP » Strings » split()

Syntax:
array split(string separator, string s [, int n])
pattern
The separator pattern.
s
The string to be converted to an array.
n
Maximum number of returned elements.

This function has been deprecated as of PHP 5.3.0.

Makes an array of a string.

This function is similar to explode(), but uses regular expressions instead of just strings for the separator. The string is split where there is a match for the separator, and the portions of the string between the matches are returned as elements of an array. If the n parameter is provided, a maximum of n elements will be returned in the array.

Examples

Code:
<pre>
<?php

$s = "123a456x789";
$pattern = "[a-z]";

$a = split($pattern, $s);
print_r($a);

?>
</pre>
Output:
Array
(
   [0] => 123
   [1] => 456
   [2] => 789
)

Explanation:

The string is split at each occurrence of a letter.

See Also: