Re: Bug #15203: ereg_replace fails on strings containing backslashes
| From: | J Smith | Date: | Thu, 24 Jan 2002 17:06:19 +0000 |
| Subject: | Re: Bug #15203: ereg_replace fails on strings containing backslashes | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-78016@lists.php.net to get a copy of this message | ||
While I did reproduce this on a linux system (2.4.9 kernel) with PHP 4.1.1,
the goal of the script doesn't seem to match the description -- the regexes
are looking to replace four backslashes with two, not two backslashes with
one. (Unless you're not counting that two backslashes are actually seen as
a single backslash because they're being escaped.)
I did notice something odd, though. I wrote a similar script in Perl to see
if preg_replace was acting properly, 'cause it seemed a little wonky. It
seems the ereg is acting correctly (obviously -- it's not going to match
four (escaped) backslashes to a string of two backslashes. However, the
preg_replace is acting weird -- why is it matching a string of two
backslashes to a regex containing four? The Perl script that this should be
equivalent to is something like
$d = "\\\\";
print "--$d--" . length($d) . "\n";
$d =~ s/\\\\\\\\/\\\\/;
print "--$d--" . length($d) . "\n";
Which spits out
--\\--2
--\\--2
which matches the ereg_replace as expected, but not the preg_replace.
So I guess there is a bug there, just not with ereg_replace, but with
preg_replace.
J
Josef Svoboda wrote:
> From: josef.svoboda@email.cz
> Operating system: FreeBSD 4.2
> PHP version: 4.0.5
> PHP Bug Type: POSIX related
> Bug description: ereg_replace fails on strings containing backslashes
>
> The goal is to replace sequence of two backslashes in $text by one
> backslash. While preg_replace works, ereg_replace does not make any change
> to $text.
>
>
> echo "preg_replace\n";
> $text="\\\\";
> echo "--".$text."--".strlen($text)."\n";
> $text=preg_replace( "/\\\\\\\\/", "\\\\", $text);
> echo "--".$text."--".strlen($text)."\n";
> echo "\n";
> echo "ereg_replace\n";
> $text="\\\\";
> echo "--".$text."--".strlen($text)."\n";
> $text=ereg_replace( "\\\\\\\\", "\\\\", $text);
> echo "--".$text."--".strlen($text)."\n";
>
>
> ./configure \
> --with-mysql=/usr/local/mysql \
> --with-imap=/usr/ports/new/imap \
> --enable-track-vars \
> --enable-trans-sid
>
>