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

How to find a word in a variable

 
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
helsma
Smarty Rookie


Joined: 17 Sep 2010
Posts: 6

PostPosted: Fri Sep 17, 2010 1:22 pm    Post subject: How to find a word in a variable Reply with quote

Hi,

I have a variable $test that contain the text eg."read the description for more information" and I would like to find the word "description" in that variable.

I tried with in_array but I think it work only for array variable.

Code:
{if in_array("description",$test)}You find it{/if}


Any advice?
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Fri Sep 17, 2010 1:39 pm    Post subject: Reply with quote

{if $haystack|strstr:$needle}

or stristr for case-insensitive match
Back to top
View user's profile Send private message Visit poster's website
helsma
Smarty Rookie


Joined: 17 Sep 2010
Posts: 6

PostPosted: Fri Sep 17, 2010 4:21 pm    Post subject: Reply with quote

mohrt wrote:
{if $haystack|strstr:$needle}

or stristr for case-insensitive match


Thanks mohrt, it work fine.
Back to top
View user's profile Send private message
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