-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemplate.php
More file actions
29 lines (22 loc) · 742 Bytes
/
Copy pathTemplate.php
File metadata and controls
29 lines (22 loc) · 742 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
class Template{
private $vars = array();
public function assign($key, $value){
$this->vars[$key] = $value;
}
public function render($template_name){
$path = $template_name . '.html';
if(file_exists($path)){
$contents = file_get_contents($path);
foreach($this->vars as $key => $value){
$contents = preg_replace('/\[' . $key . '\]/', $value, $contents);
}
$contents = preg_replace('/\<\!\-\- if (.*) \-\->/', '<?php if ($1) : ?>', $contents);
$contents = preg_replace('/\<\!\-\- else \-\->/', '<?php else : ?>', $contents);
$contents = preg_replace('/\<\!\-\- endif \-\->/', '<?php endif; ?>', $contents);
eval(' ?>' . $contents . '<?php ');
}else{
exit('<h1>Template Error</h1>');
}
}
}