PHP 4.0 Bug #8986: preg_replace: "$dd" pattern in replacement string treated as a backreference

From: Date: Mon, 29 Jan 2001 18:00:55 +0000
Subject: PHP 4.0 Bug #8986: preg_replace: "$dd" pattern in replacement string treated as a backreference
Groups: php.dev 
Request: Send a blank email to php-dev+get-45205@lists.php.net to get a copy of this message
From: gwh@acm.org Operating system: linux PHP version: 4.0.4pl1 PHP Bug Type: PCRE related Bug description: preg_replace: "$dd" pattern in replacement string treated as a backreference In php_pcre.c line 630, the dollar sign '$' is also used as in indicator for a backreference, which is undocumented. This breaks any replacement string that contains the "$dd" pattern where "dd" are numerical digits. For example: <?php $test = "hello there"; $output = preg_replace("/hello/","$10.00",$test); print $output; ?> results in the output: .00 there The "$10" is taken as a back reference and resolves to NULL leaving the ".00". In my application, I need to merge user generated text that may contain dollar signs. I am using preg_replace and doing multiple keyword,value substitutions using arrays. My only workaround right now is to perform a preliminary preg_replace and insert a space after each dollar sign. -- Edit Bug report at: http://bugs.php.net/?id=8986&edit=1

« previous php.dev (#45205) next »