1

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 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

Comments

2

You want to use a modifier:

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

5 Comments

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?
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: smarty.net/manual/en/language.modifiers.php
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.
maybe this: {$v.data|regex_replace:"/^\d+,/":""|regex_replace:"/\D/":""}
Hmmm.. same thing. That is also blank O_o

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.