Any questions involving matching text strings to patterns - the pattern is called a "regular expression."
Moderator: General Moderators
phpdevuk
Forum Contributor
Posts: 220 Joined: Mon Jul 04, 2005 5:31 am
Location: UK
Contact:
Post
by phpdevuk » Thu Nov 10, 2005 10:55 am
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?
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Thu Nov 10, 2005 3:10 pm
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.
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Thu Nov 10, 2005 8:11 pm
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 » Thu Nov 10, 2005 8:34 pm
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