Last active
August 24, 2021 12:05
-
-
Save sukei/9092282 to your computer and use it in GitHub Desktop.
A Template Engine in a Tweet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* The render function is a lightweight template engine, that allows string | |
* interpolation and output escaping. | |
* | |
* ...and it fits in a tweet. | |
* | |
* @author Quentin Schuler aka Sukei <[email protected]> | |
*/ | |
function render($t,$a,$f='htmlentities') { | |
return preg_replace_callback('/\${(\w+)}/',function($m)use($a,$f){return @$f($a[$m[1]]);},$t); | |
} |
Author
sukei
commented
Feb 19, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment