Files
picea/src/Syntax/EchoSafeToken.php
T
mcndave bb29a56077 - Added while/endwhile and do/while syntaxes
- Fix the abstractclass requirement of parse() function
2022-12-19 19:36:39 +00:00

31 lines
827 B
PHP

<?php
namespace Picea\Syntax;
class EchoSafeToken implements Syntax {
public string $tokenOpen = "\{\{";
public string $tokenClose = "\}\}";
public int $flag = \ENT_QUOTES;
public string $encoding;
public bool $doubleEncode = true;
public function __construct() {
$this->encoding = ini_get("default_charset");
}
public function parse(\Picea\Compiler\Context &$context, string &$sourceCode)
{
$sourceCode = preg_replace_callback("#({$this->tokenOpen})(.*?)({$this->tokenClose})#s", function ($matches) {
$line = trim($matches[2], " \t\n\r\0\x0B;");
return "<?php echo htmlspecialchars((string) ({$line}), {$this->flag}, '{$this->encoding}', " . ($this->doubleEncode ? "true" : "false") . ") ?>";
}, $sourceCode);
}
}