I have created a very small template class based on some others' code and I can't seem to get it to work. They way it is now, the file prints the word 'Object' and that's all. Can someone help me figure out where I've gone wrong? I'd really like to keep something simple like this instead of using Smarty or another engine.
The template class:
<?PHP
// FUNCTIONS
// Checks to see if file_get_contents function exists, if it doesn't creates function manually.
if(!function_exists('file_get_contents'))
{
function file_get_contents($filename)
{
return implode('',file($filename));
}
}
// Check for magic quotes.
define('MAGIC_QUOTES_SYBASE',false);
function clean_file_input($string) {
if(get_magic_quotes_runtime()==1) {
if(MAGIC_QUOTES_SYBASE) {
$string=str_replace("''","'",$string);
}
else {
$string=stripslashes($string);
}
}
return handle_line_endings($string);
}
// Convert all line endings to "\r\n".
function handle_line_endings($string) {
$string=str_replace("\r\n","\n",$string);
$string=str_replace("\r","\n",$string);
$string=str_replace("\n","\r\n",$string);
return $string;
}
// END FUNCTIONS
// Template Class
class template_class {
var $template_file;
var $contents;
function get_template_file($template_file) {
$this->template_file=$template_file;
$this->contents=file_get_contents($template_file);
$this->contents=clean_file_input($this->contents);
return $this->contents;
}
}
?>
The file that I've been using to test... (the test_temp.html file is a basic html file that I'm trying to get to print. Later I'll add in string replace functions etc.)
<?PHP
// Require the template class
require_once ('public_html/class/temp.class.php');
$template=new template_class;
$template->get_template_file('class/templates/test_temp.html');
print ($template);
?>