From: porost at gazeta dot pl Operating system: Windows XP SP1, Apache/2.0.48 PHP version: 4.3.9 PHP Bug Type: *Regular Expressions Bug description: ereg_replace() removes the last capital letter
Description: ------------ I've found out that some combinations of special characters in regular expressions cause the ereg_replace to cut the last letter in the string, but only if it is a capital letter. Here is the code: <?php echo ereg_replace('[\+-\.,]$','','MTM') . "<br>"; echo ereg_replace('[\+-\.,]$','','mtm') . "<br>"; echo ereg_replace('[\+-\.,]$','','MTm') . "<br>"; echo ereg_replace('[\+-\.,]$','','mtM') . "<br>"; ?> IMHO one should see: MTM mtm MTm mtM but in 2 cases, the last (capital) letter is cut out and you see: MT mtm MTm mt There is an easy fix for this problem - you just have to change the regular expression from '[\+-\.,]' to '[-\.\+,]$' and voila - everything is OK. Reproduce code: --------------- <?php echo ereg_replace('[-\.\+,]$','','MTM') . "<br>"; echo ereg_replace('[-\.\+,]$','','mtm') . "<br>"; echo ereg_replace('[-\.\+,]$','','MTm') . "<br>"; echo ereg_replace('[-\.\+,]$','','mtM') . "<br>"; echo ereg_replace('[\+-\.,]$','','MTM') . "<br>"; echo ereg_replace('[\+-\.,]$','','mtm') . "<br>"; echo ereg_replace('[\+-\.,]$','','MTm') . "<br>"; echo ereg_replace('[\+-\.,]$','','mtM') . "<br>"; ?> Expected result: ---------------- MTM mtm MTm mtM MTM mtm MTm mtM Actual result: -------------- MTM mtm MTm mtM MT mtm MTm mt -- Edit bug report at http://bugs.php.net/?id=30347&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=30347&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=30347&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=30347&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=30347&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=30347&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=30347&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=30347&r=needscript Try newer version: http://bugs.php.net/fix.php?id=30347&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=30347&r=support Expected behavior: http://bugs.php.net/fix.php?id=30347&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=30347&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=30347&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=30347&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=30347&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=30347&r=dst IIS Stability: http://bugs.php.net/fix.php?id=30347&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=30347&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=30347&r=float MySQL Configuration Error: http://bugs.php.net/fix.php?id=30347&r=mysqlcfg