I'm trying to learn some more OOP, and am trying a simple template system. These are the files I have right now:
class.php
<?php
class template {
var $template;
function load($filepath) {
$this->template = file_get_contents($filepath);
}
function replace($replace, $string) {
$this->template = str_replace("#".$replace."#", $string, $this->template);
}
function display {
return $this->template;
}
}
?>
index.php
<?php
include 'class.php';
$template = new template;
$template->load('index.html');
$template->replace('name', 'My name here');
$template->replace('dadname', 'My dads name here');
$template->display();
?>
index.html
<html>
<body>
<h1>My name is: #name#</h1>
<h2>My dad's name is: #dadname#</h2>
</body>
</html>
It ends up just displaying this:
My name is: #name#
My dad's name is: #dadname#
I guess that means it's obviously fetching the template data correctly, but it's not replacing and/or outputting correctly. Can someone see what the problem is in this situation?