View Single Post
  #1 (permalink)  
Old 05-22-07, 08:04 PM
darkcarnival's Avatar
darkcarnival darkcarnival is offline
PHP/MySQL coder
 
Join Date: Jun 2003
Posts: 939
Thanks: 0
Thanked 0 Times in 0 Posts
improving my template class

hello,

i need some assistance in improving my template class to allow the use of loops.

currently it does not and i am stuck on getting it to work with loops.

an example of what i want to try:

Code:
the following users have been here for a year or longer: {users}
now thats a very basic example, but i think you get the point.

here is the template class i use, if you need anything else please let me know

PHP Code:

class template

{
  var 
$page;

  function 
template($template) {
    if (
file_exists($template))
      
$this->page join(""file($template));
    else
      die(
"Template file $template was not found.");
  }

   function 
parse($file) {
    
ob_start();
    include(
$file);
    
$buffer ob_get_contents();
    
ob_end_clean();
    return 
$buffer;
  }

  function 
replace_tags($tags = array()) {
    if (
sizeof($tags) > 0){
      foreach (
$tags as $tag => $data) {
        
$this->page eregi_replace("{" $tag "}"$data,
                      
$this->page);
        }
    }else{
      die(
"No tags designated for replacement.");
    }
  }

  function 
output() {
    echo 
$this->page;
  }

much thanks in advance
Reply With Quote