Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Replace in smarty

 
Post new topic   Reply to topic    Smarty Forum Index -> Language: German
View previous topic :: View next topic  
Author Message
tomseno
Smarty n00b


Joined: 13 Dec 2015
Posts: 2

PostPosted: Sun Dec 13, 2015 7:43 pm    Post subject: Replace in smarty Reply with quote

Hallo!

Möchte gerne bei einem Preis der als String in einem Smarty gespeichert wird durch Zeichen ersetzen.

Code:
ecomm_totalvalue: {/literal}{$PRODUCTS_PRICE|regex_replace:'/[^0-9\.]/':''}{literal}


{$PRODUCTS_PRICE} hier ist z.B. 1.300,00 EUR gespeichert - aussehen sollte es aber so: 1300.00

Dh. der Tausenderpunkt und "EUR" muss weg. und Das Komma muss als Dezimalpunkt dargestellt werden.

Kann mir bitte jemand helfe - hab obigen Ansatz von einem anderen Forum. Jedoch nach einer Woche rumprobieren bin ich noch nicht weiter.

Danke. lg
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1583

PostPosted: Sun Dec 13, 2015 11:13 pm    Post subject: Reply with quote

If I understand your request right, you want to convert textual representation of the price into numerical.
Aside from questionable feasibility of such action (not all decimal fractions could be correctly represented in binary form), something like this could work:
Code:
{$PRODUCTS_PRICE|regex_replace:'/[^0-9\,]/':''|regex_replace:'/\,/':'.'}
Back to top
View user's profile Send private message
tomseno
Smarty n00b


Joined: 13 Dec 2015
Posts: 2

PostPosted: Mon Dec 14, 2015 6:59 am    Post subject: Reply with quote

That's it!!!
thanks a lot Very Happy
Back to top
View user's profile Send private message
elpmis
Smarty Elite


Joined: 07 Jun 2007
Posts: 321

PostPosted: Mon Dec 14, 2015 7:19 am    Post subject: Reply with quote

Du solltest aber dabei bedenken, dass regex Operationen sehr performance-lastig sind.

Von daher hätte ich eher daran gedacht, den String in eine echte Zahl umzuwandeln, also z.Bsp.

Code:
{$PRODUCTS_PRICE|floatval}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Language: German 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