Re: preg_replace
- From: kenoli <kenoli.p@xxxxxxxxx>
- Date: Tue, 26 Feb 2008 16:20:07 -0800 (PST)
On Feb 26, 3:41 pm, Michael Fesser <neti...@xxxxxx> wrote:
.oO(kenoli)
Why does the following return an empty value for $string? Shouldn't
it replace the GIF at the end of the string with "gif" and return a
value of "hello.gif"?
<?php
$string = 'hello.GIF';
echo "<br/><br/>Before replacement, \$string = $string";
$old = '*GIF$';
$new = '*gif$';
$string = preg_replace($old, $new, $string);
echo "<br/><br/>After replacement, \$string = $string";
?>
At a minimum, the manual says that it should return the same string if
no match is made.
This code can't work. You should've received a warning:
Warning: preg_replace(): No ending delimiter '*' found [...]
If you want to make the entire filename lower-case, use strtolower().
If you just want to lower-case the extension, try this:
$old = '/GIF$/';
$new = 'gif';
Micha
Thanks. Your solution worked fine. Regular expressions twist my brain
every time.
Greatly appreciated,
--Kenoli
.
- References:
- preg_replace
- From: kenoli
- Re: preg_replace
- From: Michael Fesser
- preg_replace
- Prev by Date: Re: preg_replace
- Next by Date: Re: limiting download size using curl
- Previous by thread: Re: preg_replace
- Index(es):
Relevant Pages
|