Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.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
Quote tags regex php-一般情况_Php_Regex - Fatal编程技术网

Quote tags regex php-一般情况

Quote tags regex php-一般情况,php,regex,Php,Regex,我已经问了关于regex的问题,比如交替引用的,未引用的,已引用的,未引用的。。。本线程中的案例: 我意识到我需要更一般的情况下保留项目的顺序。就像被引用,被引用,被引用,被引用,被引用。。。等还有非嵌套的引号。我想应该是迭代的或者递归的。。。我将举例说明 some unquoted text11 [quote="person1"]some quoted text11[/quote] [quote="person2"]some quoted text22[/quote] [quote="pers

我已经问了关于regex的问题,比如交替引用的,未引用的,已引用的,未引用的。。。本线程中的案例:

我意识到我需要更一般的情况下保留项目的顺序。就像被引用,被引用,被引用,被引用,被引用。。。等还有非嵌套的引号。我想应该是迭代的或者递归的。。。我将举例说明

some unquoted text11
[quote="person1"]some quoted text11[/quote]
[quote="person2"]some quoted text22[/quote]
[quote="person3"]some quoted text33[/quote]
some unquoted text22
...
[quote="person4"]some quoted text44[/quote]
...
结果数组应为:

Array   //PRESERVED ORDER
        (
            [0] => Array
                (
                    ['type'] => unquoted
                    ['name'] => ''
                    ['text'] => some unquoted text11
                )
            [1] => Array
                (
                    ['type'] => quoted
                    ['name'] => person1
                    ['text'] => some quoted text11
                )
            [2] => Array
                (
                    ['type'] => quoted
                    ['name'] => person2
                    ['text'] => some quoted text22
                )
            [3] => Array
                (
                    ['type'] => quoted
                    ['name'] => person3
                    ['text'] => some quoted text33
                )
            [4] => Array
                (
                    ['type'] => unquoted
                    ['name'] => ''
                    ['text'] => some unquoted text22
                )

                ...

            [5] => Array
                (
                    ['type'] => quoted
                    ['name'] => person4
                    ['text'] => some quoted text44
                )

                ...
        }

正则表达式对于解决这个问题是一个糟糕的选择,因为它们不提供维护状态的能力。当您提到嵌套时所指的状态。即使对于不允许嵌套标记的简单方法,解决方案仍然依赖于了解表达式的状态,因为您希望根元素被标识为这样的状态(根据预期数组中的第一个元素)


相反,一个更好的解决方案是使用一个已经得到验证的快速单通道解析器,如,它可以做更有效的工作,并提供更易于维护的代码。

嘿,你给我们展示一下你的尝试如何?PCRE比你想象的功能强大得多,请参阅。对于这个问题,我已经有了一个正则表达式的解决方案,但我们不应该满足这个问题。