Edit report at http://bugs.php.net/bug.php?id=52118&edit=1

 ID:               52118
 User updated by:  tomasz dot slominski at gmail dot com
 Reported by:      tomasz dot slominski at gmail dot com
 Summary:          preg_replace gives bad output if matching group equals
                   whole string
 Status:           Open
 Type:             Bug
 Package:          *Regular Expressions
 Operating System: WIN XP SP3
 PHP Version:      Irrelevant

 New Comment:

Fast hack:   var_dump(preg_replace(array("/(.+)(.*)/"),
array('!$1$2'),'test')); 

gives good output (!test)


Previous Comments:
------------------------------------------------------------------------
[2010-06-18 11:25:37] tomasz dot slominski at gmail dot com

Description:
------------
preg replace is going mad when matching group equals to (.*). It seems
that 

substitution is made 2 times instead of 1.

Test script:
---------------
var_dump(preg_replace(array("/(.*)/"), array('!$1'),'test'));

var_dump(preg_replace(array("/(.*)/"), array('$1!'),'test'));

var_dump(preg_replace(array("/(.*)/"), array('!$1!'),'test'));

Expected result:
----------------
string '!test' (length=5)

string 'test!' (length=5)

string '!test!' (length=6)



Actual result:
--------------
string '!test!' (length=6)

string 'test!!' (length=6)

string '!test!!!' (length=8)


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=52118&edit=1

Reply via email to