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

Replece singular and plural forms of words at the same time?

 
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
szombe
Smarty n00b


Joined: 15 Jul 2014
Posts: 4

PostPosted: Tue Jul 15, 2014 4:52 am    Post subject: Replece singular and plural forms of words at the same time? Reply with quote

Hey there folks! Need some help replacing both singular and plural forms of words. Example titles "He is eating a hamburger", "He is eating hamburgers".

How do I replace both at the same time? I want to replace words with links coming out from those words but both either hamburget or hamburgers no matter which one occurs in the description text.

Code:
{$text.descr|default:$text.text_title|replace:"hamburger":"<a target='_blank' href='http://www.hamburgerstore.bla-bla'><b>hamburger</b></a>"|replace:"hamburgers":"<a target='_blank' href='http://www.hamburgerstore.bla-bla'><b>hamburgers</b></a>"}


This does not work, so if I do

Code:
{$text.descr|default:$text.text_title|replace:"hamburger":"<a target='_blank' href='http://www.hamburgerstore.bla-bla'><b>hamburger</b></a>"}


This makes a link from any words containing hamburget, even hamburgets but the link does not include the s at the end. How do I fix this? First I thought of if cases like if the description contains hamburger, do replace with hamburger link, if it contains hamburgers do replace with hamburgers link.

{if $text.descr|strstr:"hamburgers"}
replace function here
{elseif $text.descr|strstr:"hamburgers"}
replace function here
{else}
title variable
...
Not even sure if the above will work because hamburger is contained in hamburgers as well. Laughing
Is there a more convenient way to do it or stack it?
Thanks!
Back to top
View user's profile Send private message
szombe
Smarty n00b


Joined: 15 Jul 2014
Posts: 4

PostPosted: Thu Jul 17, 2014 12:34 pm    Post subject: Reply with quote

No chance?
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Thu Jul 17, 2014 1:39 pm    Post subject: Reply with quote

Code:
{$text.descr|default:$text.text_title|regex_replace:"/\b(hamburgers?)\b/":<a href='foo'>$1</a>"}


That will replace hamburger or hamburgers, but only if its not part of a longer word.
Back to top
View user's profile Send private message Visit poster's website
szombe
Smarty n00b


Joined: 15 Jul 2014
Posts: 4

PostPosted: Fri Jul 18, 2014 10:02 am    Post subject: Reply with quote

Will give it a try. Thanks!
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