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?

mishmash
  • 4,422
  • 3
  • 34
  • 56
vandu
  • 196
  • 1
  • 3
  • 17

3 Answers3

19

From the documentation:

{$YourVariable|replace:' ':''}
mishmash
  • 4,422
  • 3
  • 34
  • 56
6

anything between strip, all spaces will be removed.

 {strip}{/strip}
amitchhajer
  • 12,492
  • 6
  • 40
  • 53
  • As far as I'm concerned, that only removes trailing spaces. – Lucas Sep 12 '12 at 07:13
  • This will not do what he wants: http://www.smarty.net/docs/en/language.modifier.strip.tpl – mishmash Sep 12 '12 at 07:17
  • they have rtrim and ltrim in smarty http://phk.tekwire.net/demo/Smarty_xref.php5/nav.html?_functions/index.html – amitchhajer Sep 12 '12 at 07:19
  • 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. :P – mishmash Sep 12 '12 at 07:22
  • @vanneto he wants to remove trailing spaces only – amitchhajer Sep 12 '12 at 07:23
  • 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. – mishmash Sep 12 '12 at 07:25
  • the first comment made me confuse, i thought he is the questionnaire and he's is concerned about removing trailing spaces now! my bad – amitchhajer Sep 12 '12 at 07:30
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:""}
chpio
  • 896
  • 6
  • 16