strip spaces from string using smarty
Asked Answered
W

3

5

I am new to smarty.

I want to know how to remove all white-space characters from a given string in Smarty?

I have a string like "this is my string". The output should be "thisismystring".

How can I do this?

Waterer answered 7/9, 2012 at 11:15 Comment(2)
Try {$variable|replace:' ':''}.Bridgid
try $string = preg_replace('/\s+/', '', $string);Kucik
L
19

From the documentation:

{$YourVariable|replace:' ':''}
Legalism answered 12/9, 2012 at 7:14 Comment(0)
S
6

anything between strip, all spaces will be removed.

 {strip}{/strip}
Sardinia answered 12/9, 2012 at 7:13 Comment(7)
As far as I'm concerned, that only removes trailing spaces.Neuroma
This will not do what he wants: smarty.net/docs/en/language.modifier.strip.tplLegalism
they have rtrim and ltrim in smarty phk.tekwire.net/demo/Smarty_xref.php5/nav.html?_functions/…Sardinia
I don't see a reference to rtrim/ltrim in the official Smarty docs. But if they behave like trim functions usually do (remove whitespace or other chars from beginning or end) it still would not do what he wants. :PLegalism
@vanneto he wants to remove trailing spaces onlySardinia
I quote: "I have a string like "this is my string". The output should be "thisismystring"." That string doesn't even have trailing spaces. Next time, read the question please.Legalism
the first comment made me confuse, i thought he is the questionnaire and he's is concerned about removing trailing spaces now! my badSardinia
H
0

You can strip whitespace from a variable (string) by using the strip modifier, and passing an empty string to it as an argument:

{$myVar|strip:""}
Herbalist answered 15/4, 2019 at 11:19 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.