Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

eregi or instr equivalent for Smarty?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
lobster
Smarty Rookie


Joined: 14 Feb 2007
Posts: 5

PostPosted: Wed Feb 14, 2007 9:59 pm    Post subject: eregi or instr equivalent for Smarty? Reply with quote

Hello Shocked
All I'm trying to do is see if a string is within another string.. so I improvised this:

Code:
{if eregi('a', $aItem.tags)}
  ***
{/if}


which is obviously wrong Wink .. I'm very much a beginner at Smarty.. but there must be an easy way to say "if there is an 'a' in this string, then do this..", yes?

Many thanks!
LObs
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Feb 14, 2007 10:03 pm    Post subject: Reply with quote

try:

Code:
{if $aItem.tags|strstr:"a"}
...
{/if}
Back to top
View user's profile Send private message Visit poster's website
lobster
Smarty Rookie


Joined: 14 Feb 2007
Posts: 5

PostPosted: Wed Feb 14, 2007 10:51 pm    Post subject: Reply with quote

wow, very cool -- it works, thanks!

If you don't mind, how do I tell it to ignore the case of the string -- or better yet, how do you force it to convert the string to all-lowercase (or at least see it as all-lowercase) in that statement?

thanks again!
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Thu Feb 15, 2007 2:33 am    Post subject: Reply with quote

Easy...just use PHP's stristr instead of strstr.

http://php.net/manual/en/function.stristr.php

It works because any PHP function can be used as a modifier. In if statements, you can use them as functions as in your first example -- the syntax choice is yours.
Back to top
View user's profile Send private message
0aphp
Smarty n00b


Joined: 28 Apr 2008
Posts: 1

PostPosted: Mon Apr 28, 2008 8:56 am    Post subject: Reply with quote

boots wrote:
Easy...just use PHP's stristr instead of strstr.

It works because any PHP function can be used as a modifier. In if statements, you can use them as functions as in your first example -- the syntax choice is yours.


Your answer is written in a limpid style. Thanks for help.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP