php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #30627 A "userdata" parameter for preg_replace_callback
Submitted: 2004-10-31 14:01 UTC Modified: 2013-02-17 13:18 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: et@php.net Assigned:
Status: Wont fix Package: *General Issues
PHP Version: Irrelevant OS: Irrelevant
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: et@php.net
New email:
PHP Version: OS:

 

 [2004-10-31 14:01 UTC] et@php.net
Description:
------------
It would be nice if preg_replace_callback had a "userdata" parameter.

Example:
$string = "[thing 1] foo [thing 2]";
$things = array( 1 => "One thing", 2 => "Other thing");

function replace_callback($match, $data) {
    return $data[$match[1]];
}

echo preg_replace_callback('/\[thing (\d+)\]/', 'replace_callback', $string, -1, $data);

Would Output:
One thing foo Other thing


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-11-06 17:49 UTC] et@php.net
The last parameter has to be $things, of course.
 [2013-02-17 13:18 UTC] nikic@php.net
-Status: Open +Status: Wont fix -Package: Feature/Change Request +Package: *General Issues
 [2013-02-17 13:18 UTC] nikic@php.net
As we now have closures this isn't necessary anymore (as you can just use() the additional parameters).
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 04 15:01:36 2025 UTC