PHP » GoLang |
login |
register |
about
|
preg_split(PHP 4, PHP 5, PHP 7) preg_split — Split string by a regular expression Description
array preg_split
( string
$pattern
, string $subject
[, int $limit = -1
[, int $flags = 0
]] )Split the given string by a regular expression. Parameters
Return Values
Returns an array containing substrings of Examples
Example #1 preg_split() example : Get the parts of a search string
<?php The above example will output: Array ( [0] => hypertext [1] => language [2] => programming )
Example #2 Splitting a string into component characters
<?php The above example will output: Array ( [0] => s [1] => t [2] => r [3] => i [4] => n [5] => g )
Example #3 Splitting a string into matches and their offsets
<?php The above example will output: Array ( [0] => Array ( [0] => hypertext [1] => 0 ) [1] => Array ( [0] => language [1] => 10 ) [2] => Array ( [0] => programming [1] => 19 ) ) NotesTip
If you don't need the power of regular expressions, you can choose faster (albeit simpler) alternatives like explode() or str_split(). Tip
If matching fails, an array with a single element containing the input string will be returned. See Also
|
more
Recently updated
more
Most requested
more
Last requests
|