ID:               30347
 User updated by:  porost at gazeta dot pl
 Reported By:      porost at gazeta dot pl
 Status:           Bogus
 Bug Type:         *Regular Expressions
 Operating System: Windows XP SP1, Apache/2.0.48
 PHP Version:      4.3.9
 New Comment:

I must have been looking at this code with the back-side of my head not
to see the "-" in the regexp. I'm ashamed :(.

The broken regexp code has been taken from one of the open source CMS
systems (Typo3 - it is eating the last capital letter when using its
search function) so at least I'm only 99% responsible for posting this
stupid mistake ;). Once again - sorry for taking your time.


Previous Comments:
------------------------------------------------------------------------

[2004-10-07 01:11:09] [EMAIL PROTECTED]

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.

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

[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

Reply via email to