3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Renderer { function render(array $_data) { // normally you'd have some file you'd render from... $_data = $this->escapeData($_data); extract($_data, EXTR_SKIP); return <<<LIST {$foo}\n {$bar}\n {$baz}\n {$htmlSafe}\n LIST; } private function escapeData(array $data) { $safe = []; foreach ($data as $var => $value) { if (is_array($value)) { $safe[$var] = $this->escapeData($value); } else { $safe[$var] = htmlspecialchars($value); } } return $safe; } } class HtmlSafeString { private $str; function __construct($string) { $this->str = $string; } function __toString() { return $this->str; } } $renderer = new Renderer(); $unsafe = [ 'foo' => '<script>alert("xss");</script>', 'bar' => '<b>something</b>', 'baz' => '<i>foo</i>', 'htmlSafe' => new HtmlSafeString('<b>got through</b>') ]; echo $renderer->render($unsafe);
Output for git.master, git.master_jit, rfc.property-hooks
&lt;script&gt;alert(&quot;xss&quot;);&lt;/script&gt; &lt;b&gt;something&lt;/b&gt; &lt;i&gt;foo&lt;/i&gt; &lt;b&gt;got through&lt;/b&gt;

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
40.98 ms | 401 KiB | 8 Q