Home Files Tools Resume
Arizona PHP Programmer AZ PHP Developer AZ Web Developer
<?php
    
    
/**
     * PasteBuilder Dynamically parsed flatfile object for use with the templating engine
     * AZPHPGuru.com - Created by Drew Ewing on 02/05/09 
     * Based on PasteBuilder, also by Drew Ewing © 2009  
     * All rights reserved, available under no licenses  
     
     * @author Drew Ewing                                
     * @package PasteBuilder                             
     * @subpackage Flatfiles                                  
     * @copyright AZPHPGuru.com 2009 ©                   
     */

    
require_once(dirname(__FILE__)."/lib.flatfile.php");
    
    class 
ParseFile extends FlatFile {
        
        
/**
         * Parsed result HTML
         * @var string
         */
        
public $resultHTML '';
        
        
/**
         * Imported Constants
         */
        
private $startTag PB_PARSE_STARTTAG;
        private 
$endTag PB_PARSE_ENDTAG;
        
        
/**
         * Create a new ParseFile object
         * @param $filename
         * @param $type
         * @return none
         */
        
function __construct($filename$type='r') {
            
parent::__construct($filename$type);
        }
        
        
/**
         * Add a simple tag parse definition
         * @param $variable
         * @param $value
         * @return boolean
         */
        
function addTag($variable$value) {
            
$this->parseTags[$variable] = $value;
            return 
true;
        }
        
        
/**
         * Remove a tag from the parsing logic
         * @param $variable
         * @return boolean
         */
        
function delTag($variable) {
            
$this->parseTags[$variable] = null;
            return 
true;
        }
        
        
/**
         * Transparently process all parse tags and return parsed file content
         * @return string
         */
        
function parseFile() {
            
$this->resultHTML implode("\n"$this->readBuffer);
            foreach(
$this->parseTags as $variable => $value) {
                
$this->resultHTML str_replace($this->startTag.$variable.$this->endTag$value$this->resultHTML);
            }
            
$this->resultHTML preg_replace('/'.$this->startTag.'(^'.$this->endTag.')'.$this->endTag.'/'''$this->resultHTML);
            return 
$this->resultHTML;
        }
    }
?>