vandu
vandu

Reputation: 196

strip spaces from string using smarty

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?

Upvotes: 5

Views: 22600

Answers (4)

This is what you need. {$your_variable|regex_replace:'/\s+/':''}

Upvotes: 0

chpio
chpio

Reputation: 1054

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:""}

Upvotes: 0

mishmash
mishmash

Reputation: 4458

From the documentation:

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

Upvotes: 19

amitchhajer
amitchhajer

Reputation: 12820

anything between strip, all spaces will be removed.

 {strip}{/strip}

Upvotes: 6

Related Questions