Re: [SMARTY] selecting 4 characters starting from right of string

From: Date: Thu, 17 Feb 2005 09:13:14 +0000
Subject: Re: [SMARTY] selecting 4 characters starting from right of string
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-12248@lists.php.net to get a copy of this message
FWIW: substr() takes negative values as start (2nd parameter) to be seen from the right end. (so you don't have to use strlen() to compute the 2nd parameter) substr() takes then *length* as the third paremeter, not the position (so the 3rd parameter has to be "4", not "strlen($str)") the 3rd parameter of substr is optional, and if omitted the whole rest of the string up to the end is returned. see: http://php.net/substr {assign var="str" value="alp.jpg"} {if substr($str, -4) == ".jpg"} Do this {else} Do that {/if} On Thu, Feb 17, 2005 at 09:59:37AM +0100, Steffen Eppler wrote: > Hi, > first of all, it has to be either (strlen()-4) or "jpg" instead of ".jpg". > > in smarty you can use this: > > {assign var="str" value="alp.jpg"} > {if substr($str,strlen($str)-4,strlen($str)) == ".jpg"} > Do this > {else} > Do that > {/if} > > > On Thu, Feb 17, 2005 at 04:47:30AM +0200, alp güneysel wrote: > > How can i get something like this inside of template for a variable in a > > section loop? > > > > > > ================= > > $str="alp.jpg"; > > $length=strlen($str); > > $suffix= substr($str,$length-3, $length); > > > > if ($suffix==".jpg"){ > > do this > > }else{ > > Do that > > } > > ================= > > > > i dont want to handle it in php, i want to be able to check it in my > > template... is it possible? > > > > -- > > Smarty General Mailing List (http://smarty.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > -- > Lassen Sie Ihren Gedanken freien Lauf... z.B. per FreeSMS > GMX bietet bis zu 100 FreeSMS/Monat: > http://www.gmx.net/de/go/mail > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.smarty.general (#12248) next »