remove image extension

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
phpdevuk
Forum Contributor
Posts: 220
Joined: Mon Jul 04, 2005 5:31 am
Location: UK
Contact:

remove image extension

Post by phpdevuk »

I used this regex in my smarty template to remove image extensions

Code: Select all

(\.jpg)|(\.gif)|(\.png)
looks like this in smarty

Code: Select all

{$icons[count]|regex_replace:"/(\.jpg)|(\.gif)|(\.png)/":" "}
any ideas on improving it?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Code: Select all

$image = "thenameoftheimage.jpg";
$extension = strstr($image,".");
$newimage = str_replace($extension,"",$image);
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post 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 ;)
Post Reply