T4VN is an online PHP Help community that provides PHP Tutorials, PHP Examples, PHP Scripts, PHP Support
    HOME  |  HOSTING COUPON  |  TEMPLATE  |  PHP SCRIPTS  |  LINK TO US  |  LINK  |  REGISTER | CONTACT
::: Member Login :::
 Username
 Password
 
Forgot your password ?
::: PHP Tutotal :::
  PHP Basic (7)
  PHP Advanced (4)
  PHP Database (2)
  Coding Step By Step (8)
  PHP and AJAX (0)
::: PHP Example :::
  Arrays (1)
  Code Highlighters (3)
  Database Functions (12)
  Date & Time (5)
  E-Mail (6)
  Forms (5)
  Guestbooks (1)
  Logging (2)
  Miscellaneous (10)
  Password Generators (3)
  Randomizers (3)
  String Manipulation (10)
  User Authentication (6)
::: Search On T4VN :::
::: T4VN Statistics :::
  PHP Scripts : 64
  PHP Example : 67
  PHP Tutorials : 21
  PHP News : 93
  Total Coupon : 36
  Other Tutorials :
  Member : 215
  Visitor Online : 3
  Today Visit: 267
  Total Visitor : 301289
  Most Online : 41
::: Sponsored Links :::

PR 4 For This Webpage

Vinaora Logo
Home Today :

Template Class

Author : YamahaBrez

Opens a file for a template, then replaces specified content in an array, and it can either print it to a static page, or you can use the "echo" command to print it dynamically.

Add multiple items to the array using the "replace" option and it will replace those as well with desired content added with the content array.

PHP Example :

<?php
# Template Class -> derek
class template {
  var 
$create false;
  var 
$replace = array("%content%");
  var 
$content = array("Nothing for content input.");
  var 
$tpl =  "design.html";
  
  function 
generate() {
    
$template $this->open($this->tpl);
    
    for (
$i 0$i count($this->replace); $i++) {
      
$template str_replace($this->replace[$i], $this->content[$i], $template);
    }
    
    if (
$this->create != false) {
      if (
is_file($this->create)) {
        @
chmod($this->create0777);
        @
unlink($this->create) or die("Unable to delete file to replace.  <br>Line: <strong>"__LINE__ ."</strong><br>File: <strong>"__FILE__ ."</strong>");
      }
      
      
$write_file = @fopen($this->create"w") or die("Failed to open file for writing.  <br>Line: <strong>"__LINE__ ."</strong><br>File: <strong>"__FILE__ ."</strong>");
      @
fwrite($write_file$template) or die("Failed to generate static HTML file.  <br>Line: <strong>"__LINE__ ."</strong><br>File: <strong>"__FILE__ ."</strong>");
      @
fclose($write_file) or die("Failed to close static HTML file.  <br>Line: <strong>"__LINE__ ."</strong><br>File: <strong>"__FILE__ ."</strong>");
      @
chmod($this->create0555) or die("Failed to set permissions for file.  <br>Line: <strong>"__LINE__ ."</strong><br>File: <strong>"__FILE__ ."</strong>");
      
# Log it
      
$log_location sitedir ."logs/"."_"."_".".txt";
      @
chmod($log_location0666);
      
$fp = @fopen($log_location"a+");
      @
fwrite($fp"page created -->"ip ."-"cpu ." | {$this->create} | "fulldate ." | "fulltime ."\n");
      @
fclose($fp);
      @
chmod($log_location0444);
      return(
true);
    } else {
      return(
$template);
    }
  }
  
  function 
open($file) {
    
$tpl sitedir ."includes/templates/"$file;
    
$template_open = @fopen($tpl"r");
    
$template fread($template_openfilesize($tpl)) or die("Failed to read template {$tpl}.  <br>Line: <strong>"__LINE__ ."</strong><br>File: <strong>"__FILE__ ."</strong>");
    @
fclose($template_open) or die("Failed to close template.  <br>Line: <strong>"__LINE__ ."</strong><br>File: <strong>"__FILE__ ."</strong>");
    return(
$template);
  }
}
?>



Usage Example :

PHP Example :

<?
$tpl 
= new template
$tpl->content = array("This would replace %content%"); 
echo 
$tpl->generate(); 

or 

$tpl = new template
$tpl->content = array("This would replace %content%"); 
$tpl->create "index.html"
$tpl->generate(); 
?>


Other Example
BBCode Using MySQL


::: Resources :::
  Links Directory
  Programming 2 3
  Webmaster 2 3
  Web Design 2 3
  Web Hosting 2 3
  Other Links 2 3
  Asian ShowBiz News
  Teach Seo For You
::: New Templates :::




::: Other Tutorials :::
 Program Design

  Powered By T4VN.NET - Version 2.0 - CopyRight © T4VN.NET 2005-2007