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

regex_replace: Replace ö ä ü with oe ae ue in smarty vars

 
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
smarty-user
Smarty Rookie


Joined: 08 Apr 2014
Posts: 5

PostPosted: Tue Apr 08, 2014 2:24 pm    Post subject: regex_replace: Replace ö ä ü with oe ae ue in smarty vars Reply with quote

Hello! How can I replace ö ä ü with oe ae ue in smarty variables. I try to use the modiefier regex_replace but it don't work:

|regex_replace:"/[ö, ä, ü]/":"oe, ae, ue"

Many Greetings


Last edited by smarty-user on Tue Apr 08, 2014 2:31 pm; edited 1 time in total
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Tue Apr 08, 2014 2:29 pm    Post subject: Reply with quote

no need for regex here.

Smarty 3:

|str_replace:[ö, ä, ü]:[oe, ae, ue]

Smarty 2 or 3:

|str_replace:$search:$replace

where $search and $replace are arrays.
Back to top
View user's profile Send private message Visit poster's website
smarty-user
Smarty Rookie


Joined: 08 Apr 2014
Posts: 5

PostPosted: Tue Apr 08, 2014 2:41 pm    Post subject: Reply with quote

The version is Smarty 3

|str_replace:[ö, ä, ü]:[oe, ae, ue]

if i use this appears a smaty error. Also with a single letter it dosen't work.
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Tue Apr 08, 2014 2:43 pm    Post subject: Reply with quote

oops, try this:

|str_replace:['ö','ä','ü']:['oe','ae','ue']
Back to top
View user's profile Send private message Visit poster's website
smarty-user
Smarty Rookie


Joined: 08 Apr 2014
Posts: 5

PostPosted: Tue Apr 08, 2014 2:51 pm    Post subject: Reply with quote

|str_replace:['ö','ä','ü']:['oe','ae','ue']

So appears in the frontend only "Array" instead of the string.
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Tue Apr 08, 2014 2:56 pm    Post subject: Reply with quote

Ok I will ge this! lol. Try this:

Code:
|replace:['ö','ä','ü']:['oe','ae','ue']


I forget we have a wrapper to str_replace, as the order of params does not work directly.
Back to top
View user's profile Send private message Visit poster's website
smarty-user
Smarty Rookie


Joined: 08 Apr 2014
Posts: 5

PostPosted: Tue Apr 08, 2014 3:04 pm    Post subject: Reply with quote

replace seemingly only works if is used a complete word or similar but not by single letters

http://www.smarty.net/docs/en/language.modifier.replace.tpl
http://www.smarty.net/docs/en/language.modifier.regex.replace.tpl
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Tue Apr 08, 2014 3:10 pm    Post subject: Reply with quote

It is working perfectly for me:

Code:
{"test öäü test"|replace:['ö','ä','ü']:['oe','ae','ue']}


output:

Code:
test oeaeue test
Back to top
View user's profile Send private message Visit poster's website
smarty-user
Smarty Rookie


Joined: 08 Apr 2014
Posts: 5

PostPosted: Tue Apr 08, 2014 3:33 pm    Post subject: Reply with quote

Thank you for the fast answers! Sorry, it was not the fault of Smarty that it not worked directly. Many Greetings
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