PHP无法使用嵌套的引号
我试图在我的BBcode类中实现嵌套引号。但是还没有成功 这是我试图实现的代码:PHP无法使用嵌套的引号,php,nested,bbcode,quote,Php,Nested,Bbcode,Quote,我试图在我的BBcode类中实现嵌套引号。但是还没有成功 这是我试图实现的代码: $string = ' [quote="test"] [quote="abc"]Test[/quote] test [/quote] Hello '; function parseTagsRecursive($input) { $regex = '#\[quote="(.*?)"]((?:[^[]|\[(?!/?quote=""])|(?R))+)\[/quote]#'; if
$string = '
[quote="test"]
[quote="abc"]Test[/quote]
test
[/quote]
Hello
';
function parseTagsRecursive($input)
{
$regex = '#\[quote="(.*?)"]((?:[^[]|\[(?!/?quote=""])|(?R))+)\[/quote]#';
if (is_array($input)) {
$input = '<div style="background:#282828; padding:0; color:white;">
<span style="display:block; background:#161616; margin-top:0; padding:5px;">' . $input[1] . ' wrote</span>
<span style="display:block; padding:5px; font-style:italic; font-size:12px;">'. $input[2] . '</span>
</div>';
}
return preg_replace_callback($regex, 'parseTagsRecursive', $input);
}
$output = parseTagsRecursive($string);
echo $output;
$string='1!'
[quote=“测试”]
[quote=“abc”]测试
测试
[quote]
你好
';
函数parseTagsRecursive($input)
{
$regex='\[quote=“(.*?”)((?:[^[]\[(?!/?quote=“]))|(?R))+)\[/quote]#;
if(is_数组($input)){
$input=
“.$input[1]”写入
“.$input[2]”
';
}
返回preg_replace_回调($regex,'parseTagsRecursive',$input);
}
$output=parseTagsRecursive($string);
echo$输出;
到目前为止,我得到的是:
class BBCode {
public $str;
function parse() {
$this->str = preg_replace_callback(
'#\[quote="(.*?)"]((?:[^[]|\[(?!/?quote=""])|(?R))+)\[/quote]#',
array($this, 'nestedQuotes'),
$this->str);
return $this->str;
}
function nestedQuotes($input) {
if (is_array($input)) {
$input = '<div style="background:#282828; padding:0; color:white;">
<span style="display:block; background:#161616; margin-top:0; padding:5px;">' . $input[1] . ' wrote</span>
<span style="display:block; padding:5px; font-style:italic; font-size:12px;">'. $input[2] . '</span>
</div>';
}
return $input;
}
}
$string = '
[quote="test"]
[quote="abc"]Test[/quote]
test
[/quote]
Hello
';
$b = new BBCode();
$b->str = $string;
echo $b->parse();
BBCode类{
公帑$str;
函数解析(){
$this->str=preg\u replace\u回调(
“#\[quote=“(.*?”)”((?:[^[])|\[(?!/?quote=“”))|(?R))+)\[/quote]#”,
数组($this,'nestedQuotes'),
$this->str);
返回$this->str;
}
函数nestedQuotes($input){
if(is_数组($input)){
$input=
“.$input[1]”写入
“.$input[2]”
';
}
返回$input;
}
}
$string='1
[quote=“测试”]
[quote=“abc”]测试
测试
[quote]
你好
';
$b=新的BBCode();
$b->str=$string;
echo$b->parse();
我希望有人能帮上忙。我已经搜索了很多,但还没有找到任何解决问题的方法。我想你正在寻找。现在它开始工作了
class BBCode {
function parse() {
$this->input = $this->nestedQuotes2($this->input);
}
function nestedQuotes2($input) {
if (is_array($input))
$input = '<div class="quote"><h2>' . $input[1] . ' skrev</h2><span class="txt">' . $input[2] . '</span></div>';
return preg_replace_callback('#\[quote="(.*?)"]((?:[^[]|\[(?!/?quote=""])|(?R))+)\[/quote]#', array($this, 'nestedQuotes2'), $input);
}
}
BBCode类{
函数解析(){
$this->input=$this->nestedQuotes2($this->input);
}
函数nestedQuotes2($input){
if(is_数组($input))
$input=''.$input[1].'skrev'.$input[2].';
返回preg#u replace#回调('\[quote=“(.*)”)((?:[^[]\[(?!/?quote=“]))|(?R))+)\[/quote]#',数组($this,'nestedQuotes2'),$input);
}
}