Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 赛前“你们都得到了正确的答案”;“结束标签”;_Php_Regex_Tags_Preg Match All - Fatal编程技术网

Php 赛前“你们都得到了正确的答案”;“结束标签”;

Php 赛前“你们都得到了正确的答案”;“结束标签”;,php,regex,tags,preg-match-all,Php,Regex,Tags,Preg Match All,我有一个小BBCode系统,它与preg_match_all一起解析我的标签。 现在我的问题是当我有类似的东西时 [tab] [tab_item id='tab' title='Titel'] Test Content [/tab_item] [tab_item id='tab2' title='Titel 2'] Test Content 2 [/tab_item] [/tab] 我拿到下一张结账单。在本例中,我得到的是[tab]的结束标签[/tab\u item],而不是相同的命名标

我有一个小BBCode系统,它与preg_match_all一起解析我的标签。 现在我的问题是当我有类似的东西时

[tab]

[tab_item id='tab' title='Titel']
Test Content
[/tab_item]

[tab_item id='tab2' title='Titel 2']
Test Content 2
[/tab_item]

[/tab]
我拿到下一张结账单。在本例中,我得到的是[tab]的结束标签[/tab\u item],而不是相同的命名标签[/tab]

我的代码是这样的:

    $pattern = "/\[(.*?) (.*?)](.*?)\[\/(.*?)\]/msi";
    preg_match_all($pattern, $article->text, $matches);

    $quotes = array();

    foreach($matches[2] as $id => $match)
    {

        preg_match_all('/(\w*?)=\'(.*?)\'/msi', $match, $attr_matches);

        echo $matches[1][$id]; //the first Tag [tab]
        echo $matches[4][$id]; //wrong closing Tag [/tab_item]


        $quote = array(
            'type'          =>  trim($matches[1][$id]),
            'text'          =>  trim($matches[3][$id]),
            'attr'    =>  array_combine($attr_matches[1], $attr_matches[2])
            );

        echo '<pre>'.print_r($quote,1).'</pre>';
    }
$pattern=“/\[(.*?)(.*?)](.*?\[\/(.*?)\]/msi”;
preg_match_all($pattern,$article->text,$matches);
$quotes=array();
foreach($id=>$match时匹配[2]项)
{
preg_match_all('/(\w*?)=\'(.*?)\'/msi',$match,$attr_matches);
echo$匹配[1][$id];//第一个标记[tab]
echo$matches[4][$id];//结束标记[/tab\u item]错误
$quote=数组(
'type'=>trim($matches[1][$id]),
'text'=>trim($matches[3][$id]),
'attr'=>数组\u组合($attr\u匹配[1],$attr\u匹配[2])
);
回显“”。打印($quote,1)。“”;
\[(.*?)\]((?:(?!\[\/\1\])[\s\S])*)\[\/\1\]
}
现在我的问题是,是否有可能在第一个preg_match_all中有一种变量,表示这些to标记必须相同

/\\[(.*?) (.*?)](.*?)\\[\\/\\1\\]/msi
您可以使用类似的方法来获取
[tab]
[/tab]
之间的数据。请参阅演示


我使用的模式与VK不同,但我认为两者都很好

主要区别在于,我还可以读取没有[blockqoute][/blockqoute]这样的“子标签”的标签,并且我也可以从主标签读取属性


但这并不是我想要的,而是我想要的。

我希望得到[tab]和[/tab]标记之间的全部内容,这样我就可以再次预匹配所有内容以过滤掉选项卡项……已经有很多用于PHP的BBCode库,有什么特别的原因让你不用其中一个吗?它只是为了学习和理解preg\u match\u all mechanism感谢wokring fine!:)我采用了一种不同的模式,它也可以读取主标记中的属性。稍后会将此作为答案发布