BBCODE, preg_replace and double quotes(BBCODE、PREG_REPLACE和双引号)
问题描述
preg_replace('/[quote=(.*?);(.*?)](.*?)[/quote]/ms', '<blockquote>Posted by: 1 at 2.<br/>3</blockquote>', $text);
这是我用来替换[quote=user;id]content[/quote]
bbcode的代码。无论如何,只有在POST中有一句引语的情况下,它才能正常工作。
如果我收到:
[quote=user1;1] [quote=user0;0]some content here[/quote]
this is my reply to user0 post[/quote]
它将仅替换第一个引号,其他将不会替换为<blockquote>
。
我如何修复它?
推荐答案
已测试、修复的版本
<?php
$out = '[quote=user1;1] [quote=user0;0]some content here[/quote]this is my reply to user0 post[/quote]';
$cnt = 1;
while($cnt != 0){
$out = preg_replace('/[quote=(.*?);(.*?)](.*?)[/quote]/ms', '<blockquote>Posted by: 1 at 2.<br/>3</blockquote>', $out, -1, $cnt);
}
echo $out;
http://codepad.org/3PoxBeQ5
这篇关于BBCODE、PREG_REPLACE和双引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!