note 21861 added to function.preg-split
| From: | dave at codewhore dot org | Date: | Wed, 29 May 2002 16:01:45 +0000 |
| Subject: | note 21861 added to function.preg-split | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-31161@lists.php.net to get a copy of this message | ||
The above description for PREG_SPLIT_OFFSET_CAPTURE may be a bit confusing.
When the flag is or'd into the 'flags' parameter of preg_split, each match is
returned in the form of a two-element array. For each of the two-element arrays, the first element
is the matched string, while the second is the match's zero-based offset in the input string.
For example, if you called preg_split like this:
preg_split('/foo/', 'matchfoomatch', -1, PREG_SPLIT_OFFSET_CAPTURE);
it would return an array of the form:
Array(
[0] => Array([0] => "match", [1] => 0),
[1] => Array([1] => "match", [1] => 8)
)
Note that or'ing in PREG_DELIM_CAPTURE along with PREG_SPLIT_OFFSET_CAPTURE works as well.
--
http://www.php.net/manual/en/function.preg-split.php
http://master.php.net/manage/user-notes.php?action=edit+21861
http://master.php.net/manage/user-notes.php?action=delete+21861
http://master.php.net/manage/user-notes.php?action=reject+21861