bharatesh
bharatesh

Reputation: 1022

String Replace in Smarty

May I know, how can I replace all elements within "(" with " ".

example:

this is (test) => this is

Upvotes: 1

Views: 12076

Answers (3)

luckychii
luckychii

Reputation: 351

Ron van der Heijden's response was very useful. I needed to do the same thing but with square brackets and my solution is below. I used an online regex generator to help me with the regex part.

{$var|regex_replace:"(\\[.*?\\])":""}

Upvotes: 0

Eugenius
Eugenius

Reputation: 1

A little more advanced replacing:

{$ptions_data = $c.options|replace:"value=\"{$c.content}\"":"value=\"{$c.content}\" selected=\"selected\""}

{$ptions_data}

{$tabs_data = $c.tabs|replace:"id=\"tab-{$c.content}\" class=\"tabs\" style=\"display:none\"":"id=\"tab-{$c.content}\" class=\"tabs\" style=\"display:block\""}

{$tabs_data}

Upvotes: 0

Ron van der Heijden
Ron van der Heijden

Reputation: 15070

Have you tried this?

{$var|replace:'value':'new_value'}

Followed this article

Or the regex str_replace?

{$var|regex_replace:"/[\r\t\n]/":" "}

Found here

Upvotes: 6

Related Questions