|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-10-07 01:11 UTC] iliaa@php.net
[2004-10-07 01:44 UTC] porost at gazeta dot pl
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 17:00:02 2025 UTC |
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