Page 1 of 1
remove image extension
Posted: Thu Nov 10, 2005 10:55 am
by phpdevuk
I used this regex in my smarty template to remove image extensions
looks like this in smarty
Code: Select all
{$icons[count]|regex_replace:"/(\.jpg)|(\.gif)|(\.png)/":" "}
any ideas on improving it?
Posted: Thu Nov 10, 2005 3:10 pm
by s.dot
Code: Select all
$image = "thenameoftheimage.jpg";
$extension = strstr($image,".");
$newimage = str_replace($extension,"",$image);
Posted: Thu Nov 10, 2005 8:11 pm
by Chris Corbyn
scrotaye wrote:Code: Select all
$image = "thenameoftheimage.jpg";
$extension = strstr($image,".");
$newimage = str_replace($extension,"",$image);
That'd be
strchr() -- Last occurrence of character until end of string.
strstr() does it from the *first* occurence of the string
NOTE: If you do just want to improve the regex and not use one of these other approaches it may be wise to add the "i" modifier.
Posted: Thu Nov 10, 2005 8:34 pm
by redmonkey
d11wtq wrote:That'd be
strchr() -- Last occurrence of character until end of string.
strstr() does it from the *first* occurence of the string
NOTE: If you do just want to improve the regex and not use one of these other approaches it may be wise to add the "i" modifier.
Close but no cigar,
strrchr() is the function you are looking for
