note 51272 added to function.preg-split
| From: | s at osu1 dot php dot net | Date: | Fri, 25 Mar 2005 10:11:21 +0000 |
| Subject: | note 51272 added to function.preg-split | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-86935@lists.php.net to get a copy of this message | ||
Mr.'galium at sandnarrows dot com' misunderstanding.
he wrote ' Notice the delimiters are missing', but the delimiters are not missing.
when using preg_*() functions, a pattern needs to be quoted with 'delimiters', for example
'/', '#', '@', or '(' and ')'.
in the context of preg_split(), 'the delimiters' means both,
(A)delimiters of pattern (or pattern delimiters) --which quote a pattern
(B)delimiter pattern - a pattern splits the string to array
in his first code,
<?php
preg_split('( and | or | not )',"blah and blarg or
ick",-1,PREG_SPLIT_DELIM_CAPTURE);
?>
the '(' and ')' is a delimiter A. this is same as...
<?php
preg_split('/ and | or | not /',"blah and blarg or
ick",-1,PREG_SPLIT_DELIM_CAPTURE);
// or
preg_split('! and | or | not !',"blah and blarg or
ick",-1,PREG_SPLIT_DELIM_CAPTURE);
?>
and so on...
the delimiters(A) are not missing. and the delimiter pattern(B) is ' and | or | not'.
so, It returns: Array ( [0] => blah [1] => blarg [2] => ick ). (there is no doubt nor any
bugs)
then, in the following code...
<?php
preg_split('(( and )|( or )|( not ))',"blah and blarg or
ick",-1,PREG_SPLIT_DELIM_CAPTURE);
?>
the first '(', and last ')' is a delimiter of pattern strings, and second,
third, firth '(' and ')' make subpatterns('parenthesized expression').
this is same as...
<?php
preg_split('/( and )|( or )|( not )/',"blah and blarg or
ick",-1,PREG_SPLIT_DELIM_CAPTURE);
?>
and so on...
the delimiters(A) are not missing. and the delimiter pattern(B) is '( and )|( or )|( not)'
( this is same as ' (and|or|not) ').
Sorry for my bad English. ( can you understand?)
----
Manual Page -- http://www.php.net/manual/en/function.preg-split.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+51272
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51272&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51272&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51272&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51272&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51272&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+51272&report=yes
Search -- http://master.php.net/manage/user-notes.php