gollum1990
Neues Mitglied
Hallo Forum,
ich habe ein Problem mit meiner Template Klasse, diese funktioniert nicht so recht. Es werden die Platzhalter nur ausgeben. Kann mir da jemand helfen:
tplclass.php
test.html
test.php
Ausgabe:
{FETT} {KURSIV} {UNTERSTRICHEN}
Danke für eure Hilfe.
MFG gollum1990
ich habe ein Problem mit meiner Template Klasse, diese funktioniert nicht so recht. Es werden die Platzhalter nur ausgeben. Kann mir da jemand helfen:
tplclass.php
PHP:
<?php
/******************/
/* Template Class */
/******************/
class template
{
var $file;
var $content;
var $values = array();
var $replaces = array();
/* Konstruktor */
function template($file,$content,$values,$replaces)
{
$this->file = $file;
$this->content = $content;
$this->values[] = $values;
$this->replaces[] = $replaces;
}
/* Template Inhalt einlesen und zurückgeben */
function readtemplate()
{
$tmp_file = @fopen($this->file, "r");
if(!$tmp_file)
{
echo "Datei nicht vorhanden.";
}
else
{
while(!feof($tmp_file))
{
$temp = fgets($tmp_file, 4096);
$this->content .= $temp;
}
}
}
/* Platzhalter suchen und ersetzen */
function replace()
{
for($i = 0; $i<count($this->replaces); $i++)
{
$this->content .= str_replace("{".$this->replaces[$i]."}", $this->values[$i], $this->content);
}
}
/* Inhalt des Template ausgeben */
function parse()
{
echo $this->content;
}
}
?>
test.html
HTML:
<b>{FETT}</b>
<i>{KURSIV}</i>
<u>{UNTERSTRICHEN}</u>
test.php
PHP:
<?php
include "tplclass.php";
$value = array("Test1", "Test2", "Test3");
$place = array("FETT","KURSIV","UNTERSTRICHEN");
$tpl = new template("test.html","",$value,$place);
$tpl->readtemplate();
$tpl->replace();
$tpl->parse();
?>
Ausgabe:
{FETT} {KURSIV} {UNTERSTRICHEN}
Danke für eure Hilfe.
MFG gollum1990