Last active
September 26, 2019 16:49
-
-
Save datchley/10301405 to your computer and use it in GitHub Desktop.
Quick and Dirty Template parsing in PHP
This file contains hidden or 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 template | |
| $template = "<h1>{TITLE}</h1>"; | |
| // add any template placeholder key/values here | |
| $map = array( | |
| 'TITLE' => "ExtJS Sucks" | |
| ); | |
| // Quick and dirty template parser, replace occurences of '{KEY}' with | |
| // the value in $map[KEY] defined above (returns parsed, completed template) | |
| $html = preg_replace_callback('/(?:{([^\}]+)\})/', function($matches) use($map) { | |
| return $map[$matches[1]]; | |
| }, $template); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment