【问题标题】:How to regex_replace in smarty?如何在 smarty 中使用 regex_replace?
【发布时间】:2019-10-23 23:09:25
【问题描述】:

我正在尝试在 smarty 中做一个 regex_replace,我已经绑定了以下内容,但它会打印变量名,不返回变量值。

如何替换为$another

尝试

{$title|regex_replace:"/apple/":"{$another}"}

【问题讨论】:

    标签: php regex string replace smarty3


    【解决方案1】:

    我的猜测是,我们可能不想拥有{$another},我们可以试试:

    {assign var="p_open" value="<p class='bla'>"}
    {assign var="p_text" value=$another.xyz}
    {assign var="p_close" value="</p>"}
    {assign var="replace" value=$p_open$p_text$p_close}
    
    {$title|regex_replace:"/(apple)/":$replace}
    

    Reference

    【讨论】:

    • 最后一个过滤了,但我的替换有 {$title|regex_replace:"/apple/":'

      {$another}

      '},怎么会如果有标签,类,可以使用 var 吗?
    • 另一个是全局变量,花药变量的值为橙色。所以我想使用 var 因为 var 是语言模式,当其他语言时,var 会自动检测来自 var 的值
    • 我的 {$another} 变量是这样的。 {$another.zyz}
    • 您分配了多个导致问题的变量。如果是单个 var,则可以工作。比如 {assign var="replace" value=$another.xyz}
    【解决方案2】:

    正确的验证。您需要在 replace var 上添加和关闭“(引号)标记才能在这种情况下正常工作。

    {assign var="p_open" value="<p class='bla'>"}
    {assign var="p_text" value=$another.xyz}
    {assign var="p_close" value="</p>"}
    {assign var="replace" value="$p_open$p_text$p_close"}
    
    {$title|regex_replace:"/(apple)/":$replace}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-14
      • 1970-01-01
      • 1970-01-01
      • 2012-06-19
      • 1970-01-01
      • 2021-07-03
      相关资源
      最近更新 更多