note 15814 added to function.ereg
| From: | bens at benjamindsmith dot com | Date: | Wed, 03 Oct 2001 21:05:58 +0000 |
| Subject: | note 15814 added to function.ereg | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-18538@lists.php.net to get a copy of this message | ||
Pattern matching with dashes - the dash "-" must come FIRST in a pattern. This is NOT TRUE
with preg. For example
$in='abc-123';
echo ereg_replace('[a-z-]', '', $in);
will return '-123', not '123'. Adding a slash in front of the 2nd "-",
as
echo ereg_replace('[a-z\-]','', $in);
makes no difference.
Using preg_replace would return '123'.
Change ereg_replace to
echo ereg_replace('[-a-z]', '', $in);
and you'll get '123' back. This as of php 4.0.5.
-Ben
--
http://www.php.net/manual/en/function.ereg.php
http://master.php.net/manage/user-notes.php?action=edit+15814
http://master.php.net/manage/user-notes.php?action=delete+15814
http://master.php.net/manage/user-notes.php?action=reject+15814