Req #32965 [Opn->Csd]: preg_split PREG_SPLIT_DELIM_CAPTURE

From: Date: Sun, 28 Aug 2016 13:37:36 +0000
Subject: Req #32965 [Opn->Csd]: preg_split PREG_SPLIT_DELIM_CAPTURE
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-203628@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=32965&edit=1

 ID:                 32965
 Updated by:         cmb@php.net
 Reported by:        elegua at hotmail dot com
 Summary:            preg_split PREG_SPLIT_DELIM_CAPTURE
-Status:             Open
+Status:             Closed
 Type:               Feature/Change Request
-Package:            Feature/Change Request
+Package:            PCRE related
 Operating System:   Sun
 PHP Version:        5CVS-2005-05-06 (dev)
-Assigned To:        
+Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

The behavior is intentional. Returning an array of arrays makes
sense with PREG_SPLIT_OFFSET_CAPTURE, because each substring and
its offset constitute a unit. With PREG_SPLIT_DELIM_CAPTURE,
however, it wouldn't be clear whether the delimiter should belong
to the previous or the following substring; actually, the
delimiter doesn't belong to either.

Furthermore, note that both options may be given to preg_split(),
and it may be useful to know the offset of the delimiter.


Previous Comments:
------------------------------------------------------------------------
[2005-05-06 17:05:16] elegua at hotmail dot com

Description:
------------
This is to do with Preg Split. When preg_split is used with the flag PREG_SPLIT_OFFSET_CAPTURE, it
returns an array, with the matched string, followed by the offset. 

When the flag PREG_SPLIT_DELIM_CAPTURE is used, it first returns the matched string, and then
returns the string.

I am not sure if the functionality of PREG_SPLIT_DELIM_CAPTURE should return as an array, it would
be far more useful it did work this way. Is this a bug with my version? Or, is this indeed the way
it should function?


Reproduce code:
---------------
$result="";
$operations=preg_split("/(&\d*=op)/",$ops);
   foreach($operations as $op) {
   $allOps[]=$op;
   }



Expected result:
----------------
each allOps will have an array of string and delim for each match found.

Actual result:
--------------
array(allOps[0]=>"some string",allOps[1]="delim")


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=32965&edit=1


Thread (2 messages)

« previous php.bugs (#203628) next »