Re: preg_replace



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
.



Relevant Pages

  • Re: preg_replace
    ... it replace the GIF at the end of the string with "gif" and return a ... the manual says that it should return the same string if ... If you want to make the entire filename lower-case, ...
    (alt.php)
  • Reading all frames and information of GIF [solution]
    ... Well, I've been bussy with a gif loader, because I needed all the frames. ... For each frame, the function addFrame(Image image, ... private static final String NODEPATH_HEIGHT = ... int imageHeight = Integer.parseInt(findValueWithPath(streamRoot, ...
    (comp.lang.java.programmer)
  • Re: Is there a free .GIF software?
    ... Is there a free software to generate .GIF files? ... Graphics canvas; ... // Create the bitmap and measure the size of the string. ... int width =; ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: Nominating a web page to display GIFs
    ... specific gif to be displayed on it- in which case you could use a query ... string and scripting to use the correct image ... hyperlinked to each GIF and when I click on the icon each GIF displays ... can somehow ceate a hyperlink string for each icon that marries the ...
    (microsoft.public.frontpage.programming)
  • C# method need for converting text to graphics
    ... for converting a text image to an image file in GIF or ... JPEG format. ... registering a software product, or submitting some kind ... The string on the image must be manually typed ...
    (microsoft.public.dotnet.languages.csharp)