|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
lobster Smarty Rookie
Joined: 14 Feb 2007 Posts: 5
|
Posted: Wed Feb 14, 2007 9:59 pm Post subject: eregi or instr equivalent for Smarty? |
|
|
Hello
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 .. 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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Feb 14, 2007 10:03 pm Post subject: |
|
|
try:
Code: | {if $aItem.tags|strstr:"a"}
...
{/if} |
|
|
Back to top |
|
lobster Smarty Rookie
Joined: 14 Feb 2007 Posts: 5
|
Posted: Wed Feb 14, 2007 10:51 pm Post subject: |
|
|
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 |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Thu Feb 15, 2007 2:33 am Post subject: |
|
|
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 |
|
0aphp Smarty n00b
Joined: 28 Apr 2008 Posts: 1
|
Posted: Mon Apr 28, 2008 8:56 am Post subject: |
|
|
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 |
|
|
|
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
|