php.net |  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
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: 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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-06 14:40 UTC] sniper@php.net
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 http://www.php.net/support.php 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-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 06 17:01:33 2025 UTC