Php 正则表达式,如何将内容文本放入数组?

Php 正则表达式,如何将内容文本放入数组?,php,arrays,preg-match-all,Php,Arrays,Preg Match All,所以我需要将值text 1,text 2,text 3作为数组 我的问题是: [code] [1] text 1 [2] text 2 [3] text 3 [/code] 它返回一个空值数组: $matches = preg_match_all( "/^\[\d{1,3}\](.*)/", $content, $tags ); 如何修复或修复它 Array ( [0] => Array ( ) [1] => Array

所以我需要将值text 1,text 2,text 3作为数组

我的问题是:

[code]
 [1] text 1
 [2] text 2
 [3] text 3
[/code]
它返回一个空值数组:

$matches = preg_match_all( "/^\[\d{1,3}\](.*)/", $content, $tags );
如何修复或修复它

Array
(
    [0] => Array
        (
        )

    [1] => Array
        (
        )

)
1
对于multiline,它将只返回文本1,而不是数组第一个元素中的所有代码

[code]
 [1] text 1
 Different content here
 [2] text 2 Another dif..
 [3] Also something either
  to be continues!
[/code]

而其他元素也将仅由第一个字符串结果生成。

您应该删除锚点^,并将。*改为前瞻集[^[]*


您应该放下锚定“^”,将。*改为前瞻集[^[]*


实际上,每个地方都可能有很多空格,但结构和我写的一样。@VictorCzechov这很好,但是从行的开始到第一个方括号是你想要的\s*,就像我的答案一样。试着让我知道。我做了整个内联[code][1]text 1[2]text 2[3]text 3[/code]它给了我数组,数组[pre][0]=>数组[0]=>[1]文本1[2]文本2[3]文本3[1]=>数组[0]=>文本1[2]文本2[3]文本3[1[/pre]很抱歉,评论版仍有问题,但请尽快关注问题的顶部。@VictorCzechov没问题,我已编辑了您的问题,以删除在查看答案时可以找到的内容:实际上,到处都有很多空格,但结构与我写的相同。@VictorCzechov这很好,但在线的艺术,直到第一个方括号是你想要的\s*,就像在我的回答中。试着让我知道。我做了整个内联[code][1]文本1[2]文本2[3]文本3[/code],它给了我数组,数组[pre][0]=>array[0]=>[1]文本1[2]文本2[3]文本3[1]=>数组[0]=>文本1[2]文本2[3]文本3 1[/pre]很抱歉,评论版仍有问题,但请稍后注意问题的顶部。@Victorchechov没问题,我已编辑了您的问题,以删除在查看答案时可以找到的内容:
Array
(
    [0] => Array
        (
            [0] => [1] text 1


            [1] => [2] text 2 Another dif..

            [2] => [3] Also something either

        )

    [1] => Array
        (
            [0] =>  text 1


            [1] =>  text 2 Another dif..

            [2] =>  Also something either

        )

)
1
$s =<<<EOM
[code]
 [1] text 1
 Another line
 [2] text 2
 And another line too
 [3] text 3
[/code]
EOM;

preg_match_all("/\[\d{1,3}\]([^[]*)/", $s, $tags);

print_r($tags);