ID: 30347 Updated by: [EMAIL PROTECTED] Reported By: porost at gazeta dot pl -Status: Open +Status: Bogus Bug Type: *Regular Expressions Operating System: Windows XP SP1, Apache/2.0.48 PHP Version: 4.3.9 New Comment:
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Read documentation. Previous Comments: ------------------------------------------------------------------------ [2004-10-07 00:12:06] porost at gazeta dot pl 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 this bug report at http://bugs.php.net/?id=30347&edit=1