3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = 1; $b = 2; $content = <<<BLOCK <h1>Some Html</h1> <hr> {IF:($a + $b === 3)} <b>Yes :)</b> {ELSE} <b>No :(</b> {ENDIF} Another one... {IF:($a + $b === 4)} <b>:)</b> {ELSE} <b>:(</b> {ENDIF} Some more Text BLOCK; echo render($content); function render($content) { $match = preg_match_all('/{IF:\((.*?)\)}(.*?){ELSE}(.*?)({ENDIF})/s', $content, $matches, PREG_OFFSET_CAPTURE); if (!$match) { return $content; } $beforeIf = substr($content, 0, $matches[0][0][1]); $afterIf = substr($content, $matches[4][0][1] + strlen('{ENDIF}')); $evalCondition = eval('return (' . $matches[1][0][0] . ');'); if ($evalCondition) { $ifResult = $matches[2][0][0]; } else { $ifResult = $matches[3][0][0]; } return $beforeIf . $ifResult . render($afterIf); }
Output for 4.3.3 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14
<h1>Some Html</h1> <hr> <b>Yes :)</b> Another one... <b>:(</b> Some more Text
Output for 4.3.0 - 4.3.2
Warning: Wrong value for parameter 4 in call to preg_match_all() in /in/jW9ND on line 28 <h1>Some Html</h1> <hr> {IF:(1 + 2 === 3)} <b>Yes :)</b> {ELSE} <b>No :(</b> {ENDIF} Another one... {IF:(1 + 2 === 4)} <b>:)</b> {ELSE} <b>:(</b> {ENDIF} Some more Text

preferences:
165.16 ms | 408 KiB | 5 Q