String Smarty中的字符串替换
我可以知道,如何将String Smarty中的字符串替换,string,replace,smarty,String,Replace,Smarty,我可以知道,如何将中的所有元素(“替换为”吗 例如: this is (test) => this is 你试过这个吗 {$var|replace:'value':'new_value'} 跟随 或者正则表达式str_替换 {$var|regex_replace:"/[\r\t\n]/":" "} 找到你试过这个吗 {$var|replace:'value':'new_value'} 跟随 或者正则表达式str_替换 {$var|regex_replace:"/[\r\t\n]/"
中的所有元素(“
替换为”
吗
例如:
this is (test) => this is
你试过这个吗
{$var|replace:'value':'new_value'}
跟随
或者正则表达式str_替换
{$var|regex_replace:"/[\r\t\n]/":" "}
找到你试过这个吗
{$var|replace:'value':'new_value'}
跟随
或者正则表达式str_替换
{$var|regex_replace:"/[\r\t\n]/":" "}
发现Ron van der Heijden的回答非常有用。我需要做同样的事情,但使用方括号,我的解决方案如下。我使用了一个来帮助我处理正则表达式部分
{$var|regex_replace:"(\\[.*?\\])":""}
Ron van der Heijden的回答非常有用。我需要做同样的事情,但使用方括号,我的解决方案如下。我使用了一个帮助我处理regex部分的
{$var|regex_replace:"(\\[.*?\\])":""}
更高级一点的替换:
{$ptions_data = $c.options|replace:"value=\"{$c.content}\"":"value=\"{$c.content}\" selected=\"selected\""}
{$ptions_data}
{$tabs_data = $c.tabs|replace:"id=\"tab-{$c.content}\" class=\"tabs\" style=\"display:none\"":"id=\"tab-{$c.content}\" class=\"tabs\" style=\"display:block\""}
{$tabs_data}
更高级一点的替换:
{$ptions_data = $c.options|replace:"value=\"{$c.content}\"":"value=\"{$c.content}\" selected=\"selected\""}
{$ptions_data}
{$tabs_data = $c.tabs|replace:"id=\"tab-{$c.content}\" class=\"tabs\" style=\"display:none\"":"id=\"tab-{$c.content}\" class=\"tabs\" style=\"display:block\""}
{$tabs_data}