3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $text = "foo { bar tree; bar ball/sand; snafu { string; } random { nested { value; bohica; } } }"; $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 '}': $brace_level--; unset($words[$brace_level]); break; case ';': $words[$brace_level] = trim($buf); $buf = ""; print implode(" ", $words)."\n"; break; default: $buf .= $text[$i]; } }
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
foo bar tree foo bar ball/sand foo snafu string foo nested random value foo nested random bohica