note 51230 added to function.preg-split

From: Date: Thu, 24 Mar 2005 05:22:40 +0000
Subject: note 51230 added to function.preg-split
Groups: php.notes 
Request: Send a blank email to php-notes+get-86869@lists.php.net to get a copy of this message
'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. ---- Manual Page -- http://www.php.net/manual/en/function.preg-split.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51230 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51230&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51230&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51230&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51230&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51230&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51230&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#86869) next »