- var_dump: documentation ( source)
- preg_match_all: documentation ( source)
<?php
$text = "{tab=Text1}
<p> nejaky</p><p>dlouhy text 1</p> ...
{tab=Text2}
<p>Jiny text...{test}.</p>
{tab=Text3}
....
{/tab}
{tab=Text4}
<p> nejaky</p><p>dlouhy text 1</p> ...
";
$pattern="/(?:{tab=(?P<tab>[^}]+)})\n(?P<content>(?:(?!\n{\/?tab[^}]*}).)*)/s";
preg_match_all($pattern, $text, $matches);
$result = [];
if($matches) foreach($matches["tab"] as $i => $name) {
if(isset($result[$name])) throw new Exception("Duplicate tab name '{$name}'");
$result[$name] = $matches["content"][$i];
}
var_dump($result);