php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45748 preg_replace_callback : named subpattern not implemented
Submitted: 2008-08-07 23:34 UTC Modified: 2008-08-08 09:44 UTC
From: xxorax at gmail dot com Assigned:
Status: Closed Package: PCRE related
PHP Version: 5.2.6 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
30 + 7 = ?
Subscribe to this entry?

 
 [2008-08-07 23:34 UTC] xxorax at gmail dot com
Description:
------------
named subpattern is not passed with their names in the array of the callback function in preg_replace_callback.

this is the same bug of Bug #37911 (1 year) but it is not fixed !

thanks

Reproduce code:
---------------
$regex = '#(?P<int>\d+):(?P<text>\w+)#';

$data = <<<TEST
zedz:fzef
234:zefrfr
13232erf:erfrfe
345345:rgrtgtr
TEST;

function func ($m) {
	print_r($m);
	return "match";
}
echo $data."\n";
echo preg_replace_callback($regex, 'func', $data);

Expected result:
----------------
zedz:fzef
234:zefrfr
13232erf:erfrfe
345345:rgrtgtr
Array
(
    [0] => 234:zefrfr
    [int] => 234
    [text] => zefrfr
)
Array
(
    [0] => 345345:rgrtgtr
    [int] => 345345
    [text] => rgrtgtr
)
zedz:fzef
match
13232erf:erfrfe
match

Actual result:
--------------
zedz:fzef
234:zefrfr
13232erf:erfrfe
345345:rgrtgtr
Array
(
    [0] => 234:zefrfr
    [1] => 234
    [2] => zefrfr
)
Array
(
    [0] => 345345:rgrtgtr
    [1] => 345345
    [2] => rgrtgtr
)
zedz:fzef
match
13232erf:erfrfe
match

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-08 09:44 UTC] lbarnaud@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

This had been fixed in 5.3 but not in older branches. This is now
fixed in 5.2 and will be available in future 5.2 snapshots.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 03:01:29 2024 UTC