【问题标题】:How to set variable in preg_replace (html syntax)?如何在 preg_replace(html 语法)中设置变量?
【发布时间】:2012-06-29 11:09:59
【问题描述】:
$con = preg_replace('#(<input type="text"[^>]+?>)#', '<input type="hidden" name="dog" value="$a">${1}', $content);

如何将值设置为变量?这我得到的不正确($a,语法?)

【问题讨论】:

    标签: php preg-replace


    【解决方案1】:

    你需要$a还是变量$a的内容

    '<input type="hidden" name="dog" value="'.$a.'">${1}'
    

    【讨论】:

      【解决方案2】:

      我认为应该只是 1 美元,而不是 ${1}。这就是我一直使用的方法,而且似乎有效。

      【讨论】:

      • ${1} - 它工作。我将添加 $a 作为值 -> - 这是不正确的。
      猜你喜欢
      • 1970-01-01
      • 2012-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-02
      • 1970-01-01
      相关资源
      最近更新 更多