zx.
zx.

Reputation: 249

Using str_replace with smarty variable

Basically I just want to strip out a part of my smarty variable contents.

{foreach from=$_sequences key=k item=v}

{if $v.pri == $smarty.get.cf && $v.type == 'TTS'}

{$v.data}

{/if}

{/foreach}

{$v.data} will echo out 21,5555555555

I want it to only echo out 5555555555. I tried str_replace but couldn't get it working..

str_replace('"','',${v.data});//   - doesn't work

str_replace('"','',$v.data);// - doesn't work

What would be the best way I can accomplish this?

Upvotes: 1

Views: 11005

Answers (2)

Thomas Eimers
Thomas Eimers

Reputation: 405

This is the way str_replace in Smarty works:

{"replace_this_text"|str_replace:"I am the new text":$value}

General, Smarty's pipe '|' operator use the value before the pipe as the first argument for the called function, which is the search text in case of str_replace.

Upvotes: 6

lfagundes
lfagundes

Reputation: 3068

You want to use a modifier:

{$v.data|regex_replace:"/^\d+,/":""}

Upvotes: 2

Related Questions