tags:

views:

1018

answers:

1

Hello,

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?

+2  A: 

You want to use a modifier:

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

lfagundes
Hey, thanks a lot! That is just what I needed. I will remember this from now on.Say if $v.data echoed out "test" with the quotes around it. How would you use regex to remove the quotes and just echo out test?
zx
try this: {$v.data|regex_replace:'/^"\d+,(\d+)"/':"$1"}I'm not sure how capturing parenthesis is exactly like this in Smarty, but in case it doesn't work you can chain modifiers:{$v.data|regex_replace:'/^\d+,':""|replace:'"':''}More on modifiers: http://www.smarty.net/manual/en/language.modifiers.php
lfagundes
Thank you for your prompt response! I tried the first one, and it still had the "'s. The second one doesn't display any data and is just blank.
zx
maybe this: {$v.data|regex_replace:"/^\d+,/":""|regex_replace:"/\D/":""}
lfagundes
Hmmm.. same thing. That is also blank O_o
zx