【问题标题】:preg_replace() warning : Delimiter must not be alphanumeric or backslash [duplicate]preg_replace() 警告:分隔符不能是字母数字或反斜杠 [重复]
【发布时间】:2023-04-11 12:34:01
【问题描述】:

我有这段代码是为了替换 div 里面的内容,">" 和 "

$pageParticulier->post_content=preg_replace("#>"+$old_instance['title']+"<#", ">"+$new_instance['title']+"<",$pageParticulier->post_content);

我有这个警告preg_replace(): Delimiter must not be alphanumeric or backslash

但我不明白的是,我已经为模式设置了分隔符。

【问题讨论】:

  • +替换为连接操作符-点-"#>".$old_instance['title']."<#"

标签: php wordpress preg-replace


【解决方案1】:

php 中的字符串连接使用句点. 而非加号+ 处理:

$pageParticulier->post_content = preg_replace(
        "#>" . $old_instance['title'] . "<#", 
        ">" . $new_instance['title'] . "<",
        $pageParticulier->post_content
    );

【讨论】:

  • 该死!合并js和php,不错...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-02-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多