- print_r: documentation ( source)
- preg_match_all: documentation ( source)
<?php
$data ='Hello
Test1
Begin
* nm: 866 444 988
* nm: 08 66
# allowed * nm: 77 2
End
* nm: 0
Hello
Test1
Begin
* nm: 866 444 988
* nm: 08 66
441
# allowed * nm: 77 2
Ed
* nm:0';
$pattern = <<<'EOD'
~
(?:\G(?!\A)|^Begin$)
(?> \R
(?:
(?:\Q# allowed \E)? \Q* nm:\E
|
(?=End$)
|
.*
)
)* (?:[ ] \K (\d+) | \z)
~xm
EOD;
$ebFlag = false; # set if the end boundary is needed
if (preg_match_all($pattern, $data, $m) ) {
print_r($m);
}