2015-07-13 110 views
0

我在堆栈上很新,所以对我来说容易犯错,我会尝试修复如果我做错了什么。Php反斜杠问题wordpress

我正在使用一个插件,但修改了很多。我在哪里需要文本peice的,并将其转换为一个我想

例如阶段:

$cross_post_content = preg_replace('/<strong>/', '[b]', $cross_post_content); 
$cross_post_content = preg_replace('/<strong>/', '[/b]', $cross_post_content); 

这条线将取代这条线将取代[CODE]为[B] [/CODE]

$cross_post_content = preg_replace('/<strong>/', '[b]', $cross_post_content); 

的问题是要撤消强烈,它是

</strong> 

,但它给我的问题,也许因为它使用反斜线,有人可以帮忙吗?

回答

0

在正则表达式中,/具有特殊含义,从字面上看,您在第三个字符后终止正则表达式。为了绕开这个问题,必须取消它用一个反斜杠,像这样

$cross_post_content = preg_replace('/<\/strong>/', '[/b]', $cross_post_content); 

有关的preg_replace的更多信息,请参阅http://php.net/manual/en/function.preg-replace.php。为正则表达式帮助本身看到http://php.net/manual/en/reference.pcre.pattern.syntax.php

+0

完美的作品,谢谢! –