Php 反斜杠问题 wordpress
Php backslash issue wordpress
我在堆栈上还很新,所以当我犯错误时请放轻松,如果我做错了什么,我会尽力改正。
我正在使用一个插件,但修改了很多。我正处于需要一段文本并将其转换为我想要的文本的阶段
例如:
$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>
但它给我带来了问题,可能是因为它使用了反斜杠,有人可以帮忙吗?
在正则表达式中,/ 有特殊含义,字面意思是在第三个字符之后终止正则表达式。为了解决这个问题,你必须使用反斜杠取消它,就像这样
$cross_post_content = preg_replace('/<\/strong>/', '[/b]', $cross_post_content);
有关 preg_replace 的更多信息,请参阅 http://php.net/manual/en/function.preg-replace.php. For regex help itself see http://php.net/manual/en/reference.pcre.pattern.syntax.php
我在堆栈上还很新,所以当我犯错误时请放轻松,如果我做错了什么,我会尽力改正。
我正在使用一个插件,但修改了很多。我正处于需要一段文本并将其转换为我想要的文本的阶段
例如:
$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>
但它给我带来了问题,可能是因为它使用了反斜杠,有人可以帮忙吗?
在正则表达式中,/ 有特殊含义,字面意思是在第三个字符之后终止正则表达式。为了解决这个问题,你必须使用反斜杠取消它,就像这样
$cross_post_content = preg_replace('/<\/strong>/', '[/b]', $cross_post_content);
有关 preg_replace 的更多信息,请参阅 http://php.net/manual/en/function.preg-replace.php. For regex help itself see http://php.net/manual/en/reference.pcre.pattern.syntax.php