note 51272 deleted from function.preg-split by betz

From: Date: Fri, 25 Mar 2005 11:34:00 +0000
Subject: note 51272 deleted from function.preg-split by betz
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-86937@lists.php.net to get a copy of this message
Note Submitter: s ---- 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?)

« previous php.notes (#86937) next »