Re: preg_replace
- From: Michael Fesser <netizen@xxxxxx>
- Date: Wed, 27 Feb 2008 00:41:07 +0100
..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
.
- Follow-Ups:
- Re: preg_replace
- From: kenoli
- Re: preg_replace
- References:
- preg_replace
- From: kenoli
- preg_replace
- Prev by Date: preg_replace
- Next by Date: Re: preg_replace
- Previous by thread: preg_replace
- Next by thread: Re: preg_replace
- Index(es):
Relevant Pages
|