Supportnet / Forum / Skripte(PHP,ASP,Perl...)
eregi_replace mit function ?
Frage
Hallo,
ich hab ein Problem. Ich möchte eine kleine Template Engine bauen. In den Dateien soll das includen von anderen Dateien möglich sein.
Der Befehl dazu sieht in der Template Datei so aus :
[code]<!--INCLUDE 'overall_header.html'-->[/code]
Nun möchte ich das durch ein eregi_replace durch den inhalt der Datei erstezen. Das habe ich mir so vorgestellt :
[code]eregi_replace("\<!--INCLUDE '(.*)'-->",$this->getcontent("\\1"),$this->htmldata);[/code]
dies geht aber leider net so wie ich mir das dachte.
Hier nochmal die ganze Klasse in der Übersicht :
[code]
<?php
//Template Engine (class.template.php) v1.00
class template
{
var $htmldata = "";
var $styledir = "style/";
function template($file)
{
$fileopen = fopen($this->styledir.$file,"r");
$this->htmldata = fread($fileopen,filesize($this->styledir.$file));
fclose($fileopen);
$this->parse();
}
function parse()
{
$temp = eregi_replace("\<!--INCLUDE '(.*)'-->",$this->getcontent("\\1"),$this->htmldata);
print($temp);
}
function getcontent($file)
{
$fileopen = fopen($this->styledir.$file,"r");
$return = fread($fileopen,filesize($this->styledir.$file));
fclose($fileopen);
return $return;
}
}
?>[/code]
Ich hoffe ihr könnt mir helfen.
mfg
Remon
Antwort 1 von Fassy91
ok habs anders gelöst :
Aber ich hab ein Problem mit dem Reg Ex :
$temp = preg_match_all("/<!--INCLUDE '[a-zA-Z]'-->/",$this->htmldata,$regs);
Kann mir da einer helfen ?
//Includes die vom Template kommen
$temp = preg_match_all("/<!--INCLUDE '[a-zA-Z]'-->/",$this->htmldata,$regs);
$i = 0;
foreach($regs AS $file)
{
if ($i != 0 AND $last != $file)
{
$this->htmldata = str_replace("<!--INCLUDE '{$file}'-->",$this->getcontent($file),$this->htmldata);
$last = $file;
}
$i++;
}
unset($regs);
unset($temp);Aber ich hab ein Problem mit dem Reg Ex :
$temp = preg_match_all("/<!--INCLUDE '[a-zA-Z]'-->/",$this->htmldata,$regs);
Kann mir da einer helfen ?

