From: c dot luxig at lmcsoft dot com Operating system: Win XP PHP version: 4.3.2 PHP Bug Type: *Regular Expressions Bug description: dynamic variables in preg_replace
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. -- Edit bug report at http://bugs.php.net/?id=24061&edit=1 -- Try a CVS snapshot: http://bugs.php.net/fix.php?id=24061&r=trysnapshot Fixed in CVS: http://bugs.php.net/fix.php?id=24061&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=24061&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=24061&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=24061&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=24061&r=support Expected behavior: http://bugs.php.net/fix.php?id=24061&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=24061&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=24061&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=24061&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=24061&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=24061&r=dst IIS Stability: http://bugs.php.net/fix.php?id=24061&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=24061&r=gnused