Forum Moderators: coopster
<?php
// template.php
class template
{
public $output;
// Function to set the file names
function set_filenames($filenames = array())
{
foreach ($filenames as $files)
{
$this->output = file_get_contents($files);
return $this->output;
}
}
// Function to define the language file
function define_language($language = array())
{
foreach ($language as $placeholder => $conversion)
{
$this->output = str_replace('{' . $placeholder . '}',$conversion,$this->output);
}
echo $this->output;
}
}
?> <?php
// viewcontent.php
// Include the file
require('template.php');
// Instantiate the class
$template = new template();
$lang = array(
'TITLE'=>'Template Parser',
'CONTENT'=>'<p>This is an example of the template parser.</p>',
'MORE_CONTENT'=>'<p>This is some more content.</p>',
'EXAMPLE_LINK'=>'<p><a href="link.php">Example Link</a></p>',
'CONTENT_AGAIN'=>'<p>Footer content.</p>'
);
// Display the page
$template->set_filenames(array(
'overall_content.html',
'overall_footer.html'));
$template->define_language($lang);
?>
function set_filenames($filenames = array())
{
$this->output="";
foreach ($filenames as $files)
{
$this->output .= file_get_contents($files);
}
return $this->output;
}