Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用str_替换为smarty变量_Php_Smarty - Fatal编程技术网

Php 使用str_替换为smarty变量

Php 使用str_替换为smarty变量,php,smarty,Php,Smarty,基本上,我只想去掉smarty变量内容的一部分 {foreach from=$_sequences key=k item=v} {if $v.pri == $smarty.get.cf && $v.type == 'TTS'} {$v.data} {/if} {/foreach} {$v.data}将回显2155555 我希望它只回显5555。我尝试了str\u replace,但无法使其工作 str_replace('"','',${v.data});// - d

基本上,我只想去掉smarty变量内容的一部分

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

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

{$v.data}

{/if}

{/foreach}
{$v.data}
将回显2155555

我希望它只回显5555。我尝试了
str\u replace
,但无法使其工作

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

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

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

您想使用修饰符:

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

要使用修改器:

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

这是Smarty中str_replace的工作方式:

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

一般情况下,Smarty的管道“|”运算符使用管道前的值作为被调用函数的第一个参数,这是str_replace情况下的搜索文本。

这是str_replace在Smarty中的工作方式:

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

一般来说,Smarty的管道“|”运算符使用管道前面的值作为被调用函数的第一个参数,这是str_replace情况下的搜索文本。

嘿,非常感谢!这正是我所需要的。从现在起我会记住这一点。假设$v.data在“test”后面加上引号。您如何使用regex删除引号,然后只回显测试?请尝试以下方法:{$v.data | regex_replace:'/^“\d+,(\d+)/':“$1”}我不确定在Smarty中捕获括号与此完全相同,但如果它不起作用,您可以链接修饰符:{$v.data | regex_replace:'/^\d+,':'':'':'';replace:':'':'}更多关于修饰语的信息:谢谢你的及时回复!我试了第一个,但仍然有“'s”。第二个不显示任何数据,只是空白。可能是这样:{$v.data | regex_replace:“/^\d+,/”:”;regex_replace:“/\d/”:”}hmm。。同样的事情。那也是空白哦哦,谢谢!这正是我所需要的。从现在起我会记住这一点。假设$v.data在“test”后面加上引号。您如何使用regex删除引号,然后只回显测试?请尝试以下方法:{$v.data | regex_replace:'/^“\d+,(\d+)/':“$1”}我不确定在Smarty中捕获括号与此完全相同,但如果它不起作用,您可以链接修饰符:{$v.data | regex_replace:'/^\d+,':'':'':'';replace:':'':'}更多关于修饰语的信息:谢谢你的及时回复!我试了第一个,但仍然有“'s”。第二个不显示任何数据,只是空白。可能是这样:{$v.data | regex_replace:“/^\d+,/”:”;regex_replace:“/\d/”:”}hmm。。同样的事情。这也是空白的