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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 12:01:27 2024 UTC