|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24061 dynamic variables in preg_replace
Submitted: 2003-06-06 10:00 UTC Modified: 2003-06-06 14:40 UTC
From: c dot luxig at lmcsoft dot com Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 4.3.2 OS: Win XP
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.
Block user comment
Status: Assign to:
Bug Type:
From: c dot luxig at lmcsoft dot com
New email:
PHP Version: OS:


 [2003-06-06 10:00 UTC] c dot luxig at lmcsoft dot com
Dynamic variables were not used in preg_replace().
I want searching html code for the tag "<usr my_var>" and want to replace this tag by the HTTP_POST or HTTP_GET var "my_var", but it doesn't work.

Here is my regexp:
$modified = '[...]<usr my_var>[...]';
$my_var = 'content';

$modified = preg_replace("/<usr\s+?(.*?)\s*?>/ims", ${"$1"}, $modified, -1);
Output: [...][...] (replaced by empty string)

This expression match to <usr my_var> and if i do the following preg_replace works correct:
$modified = preg_replace("/<usr\s+?(.*?)\s*?>/ims", "$1", $modified, -1);
Output: [...]my_var[...]

And this also doesn't work:
$modified = preg_replace("/<usr\s+?(.*?)\s*?>/ims", ${$my_var}, $modified, -1);
Output: [...][...] (replaced by empty string)

This is the problem.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-06 14:40 UTC]
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

Ask support questions elsewhere, thank you.

PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu Jan 27 06:03:35 2022 UTC