From: bloudon at townnews dot com Operating system: Slackware Linux 10 PHP version: 5CVS-2006-08-07 (snap) PHP Bug Type: PCRE related Bug description: Match-all-or-none pattern in preg_replace duplicates repl. text
Description: ------------ When using preg_replace with a pattern of '/(.*)/' or similar, the returned string will contain two instances of the replacement text, with the second instance appended to the first and given empty backreferences. This behavior does not occur when the pattern is anchored to the start of the string: '/^(.*)/'. ./configure --with-apxs --enable-versioning --enable-memory-limit --with-mysql=/usr --enable-xslt --with-xslt-sablot --with-gd --with-jpeg-dir=/usr --with-zlib-dir=/usr --with-ttf=/usr --with-freetype-dir=/usr --enable-gd-native-ttf --enable-bcmath --with-mime-magic Reproduce code: --------------- <?php echo preg_replace('/(.*)/', 'a$1b', 'foo') ."\n"; echo preg_replace('/(.*)$/', 'a$1b', 'foo') ."\n"; echo preg_replace('/^(.*)/', 'a$1b', 'foo') ."\n"; echo preg_replace('/^(.*)$/', 'a$1b', 'foo') ."\n"; echo preg_replace('/.*/', 'ab', 'foo') ."\n"; echo preg_replace('/f*/', 'ab', 'foo') ."\n"; ?> Expected result: ---------------- afoob afoob afoob afoob ab aboo Actual result: -------------- afoobab afoobab afoob afoob abab ababoaboab -- Edit bug report at http://bugs.php.net/?id=38368&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=38368&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=38368&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=38368&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=38368&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=38368&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=38368&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=38368&r=needscript Try newer version: http://bugs.php.net/fix.php?id=38368&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=38368&r=support Expected behavior: http://bugs.php.net/fix.php?id=38368&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=38368&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=38368&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=38368&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=38368&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=38368&r=dst IIS Stability: http://bugs.php.net/fix.php?id=38368&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=38368&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=38368&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=38368&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=38368&r=mysqlcfg