<?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); }
You have javascript disabled. You will not be able to edit any code.