使用str_replace和smarty变量

时间:2010-04-29 11:52:32

标签: php smarty

基本上我只想删除一部分我聪明的变量内容。

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

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

{$v.data}

{/if}

{/foreach}

{$v.data}将回显21,5555555555

我希望它只能回显5555555555.我试过str_replace但是无法让它正常工作..

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

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

我能做到这一点的最佳方式是什么?

2 个答案:

答案 0 :(得分:6)

这是Smarty中str_replace的工作方式:

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

将军,Smarty的烟斗'|'运算符使用管道前的值作为被调用函数的第一个参数,这是str_replace的搜索文本。

答案 1 :(得分:2)

您想要使用修饰符:

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