strip spaces from string using smarty

18,799

Solution 1

From the documentation:

{$YourVariable|replace:' ':''}

Solution 2

anything between strip, all spaces will be removed.

 {strip}{/strip}
Share:
18,799
vandu
Author by

vandu

Passionate UI developer

Updated on June 06, 2022

Comments

  • vandu
    vandu almost 2 years

    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?

  • Lucas
    Lucas over 11 years
    As far as I'm concerned, that only removes trailing spaces.
  • mishmash
    mishmash over 11 years
    This will not do what he wants: smarty.net/docs/en/language.modifier.strip.tpl
  • amitchhajer
    amitchhajer over 11 years
  • mishmash
    mishmash over 11 years
    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
  • amitchhajer
    amitchhajer over 11 years
    @vanneto he wants to remove trailing spaces only
  • mishmash
    mishmash over 11 years
    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.
  • amitchhajer
    amitchhajer over 11 years
    the first comment made me confuse, i thought he is the questionnaire and he's is concerned about removing trailing spaces now! my bad