PHP: preg_replace between "<<" and ">


PHP: preg_replace between "<<" and ">>"

嗨,我想用自定义div类替换"<<"answers">>"之间的内容,我该怎么做?

我尝试了一些正则表达式,但它不起作用。

$con = preg_replace ('/<<(.*?)>>/s', '<div>$1</div>', $con);

我建议将<和>在字符类中:

preg_replace('/[<]{2}(.*?)[>]{2}/s', '<div>$1</div>', $con);

逃离他们也应该工作

preg_replace('/'<'<(.*?)'>'>/s', '<div>$1</div>', $con);

但CC001上面的评论是正确的:这两者都不需要。