Php 如何在preg_replace的正则表达式中使用变量?

Php 如何在preg_replace的正则表达式中使用变量?,php,Php,我有如下代码: $titles=$key->post_title;//$titles just contain some strings. $replace='<a target="_blank" href="http://wiki:8888/wiki/'.$titles.'">'.$titles.'</a>'; //this is want I want to do ,use $titles in the regex. $regex

我有如下代码:

    $titles=$key->post_title;//$titles just contain some strings.
    $replace='<a target="_blank" href="http://wiki:8888/wiki/'.$titles.'">'.$titles.'</a>';
    //this is want I want to do ,use $titles in the regex.
    $regex = '/'.$titles.'/';
    $content = preg_replace($regex, $replace, $content, 1);
或:


我错在哪里?

如果你用一个简单的字符串代替变量,警告就会消失?也许考虑使用PREGYQUOLD()是的,当我使用字符串像$ReGeX =“/标题”时,它工作正常,但需要使用变量。
$regex = "/".$titles."/";
$regex = "/$titles/";