We Recommend

Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.


Posted By

fris on 03/08/08


Tagged

file template


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

ctronci


simple template engine


Published in: PHP 


  1. <?
  2.  
  3. function parse_template($filename) {
  4. $template_contents = "";
  5.  
  6. if(!file_exists($filename)) {die("Template ($filename) does note exist.");}
  7. if(!$fp = fopen($filename,'r')) {die("Could not open template ($filename).");}
  8.  
  9. $lines = file($filename);
  10.  
  11. $globals = split(",",array_shift($lines));
  12. foreach ($globals as $gbl) {global $$gbl;}
  13.  
  14. $template_contents = implode("",$lines);
  15.  
  16. $template_contents = preg_replace("/\[(\w+)\]/e","\$\$1",$template_contents);
  17.  
  18. return $template_contents;
  19. }
  20. ?>

Report this snippet 

You need to login to post a comment.