$value) { if ($value === null) { echo "\n"; continue; } unset($conditional); if (is_array($value)) { $conditional = $value[0]; if (!is_array($conditional)) { $conditional = array($conditional); } $value = $value[1]; } $allow = true; if (isset($conditional)) { foreach ($conditional as $test) { if (!$allow) { break; } if (preg_match('/^!?\$(\S+)/', $test, $matches)) { $invert = (strpos($test, '!') === 0); $components = explode('.', $matches[1]); $tier = $textOutput; foreach ($components as $index => $c) { if (is_array($tier) && !isset($tier[$c])) { if (!$invert) { $allow = false; } break; } if ($index == count($components) - 1 && is_array($tier)) { if ((!$tier[$c] && !$invert) || ($tier[$c] && $invert)) { $allow = false; } break; } else if (!is_array($tier)) { $allow = false; break; } $tier = $tier[$c]; } } } } if (!$allow) { continue; } if (preg_match_all('/(?<=^|\s)\$(\S+)(?=$|\s)/', $value, $matches, PREG_OFFSET_CAPTURE)) { array_shift($matches); $matches = $matches[0]; $matches = array_reverse($matches); foreach ($matches as $m) { $resolvedKeyPath = ''; $components = explode('.', $m[0]); $tier = $textOutput; foreach ($components as $index => $c) { if (is_array($tier) && !isset($tier[$c])) { $allow = false; break 2; } if ($index == count($components) - 1 && is_array($tier)) { $resolvedKeyPath = (string) $tier[$c]; break; } else if (!is_array($tier)) { $allow = false; break 2; } $tier = $tier[$c]; } $value = substr($value, 0, $m[1] - 1) . strip_tags($resolvedKeyPath) . substr($value, $m[1] + strlen($m[0])); } } if (!$allow) { continue; } echo $label . ': ' . $value . "\n"; } ?>