This snippet here simply goes through the array, char by char. And decides on {
, }
and ,
whether to go one step up or down or if the actual string needs to be printed.
$buf = "";
$brace_level = 0;
$words = array();
for ($i = 0; $i < strlen($text); $i++) {
switch ($text[$i]) {
case '{':
$words[$brace_level] = trim($buf);
$buf = "";
$brace_level++;
break;
case '}':
unset($words[$brace_level]);
$brace_level--;
unset($words[$brace_level]);
break;
case ';':
$words[$brace_level] = trim($buf);
$buf = "";
print implode(" ", $words)."\n";
break;
default:
$buf .= $text[$i];
}
}