note 51230 deleted from function.preg-split by colder
| From: | colder@php.net | Date: | Mon, 18 Jun 2007 19:39:40 +0000 |
| Subject: | note 51230 deleted from function.preg-split by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-127663@lists.php.net to get a copy of this message | ||
Note Submitter: s
----
'galium at sandnarrows dot com' misunderstanded.
he wrote ' Notice the delimiters are missing', but the delimiters are not missing.
when using preg_*() functions, you need to quote pattern with 'delimiters', for example
'/', '#', '@', or '(' and ')'.
in the context of preg_split(), 'the delimiters' means both,
(A)delimiters of pattern - which quote pattern
(B)delimiter pattern - which split 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 of pattern strings(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...
?>
so, It returns: Array ( [0] => blah [1] => blarg [2] => ick ). (there is no doubt nor any
bugs)
the delimiters(A) are not missing. and the delimiter pattern(B) is ' and | or | not'.
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?)
hope this can help some one.
and also hope, some one rewite this to good English.