naja hier mal mein code
Code: Alles auswählen
<?php
class tpl {
var $path;
var $contents;
var $content;
var $handle;
############ Für das Parsen von normalen dateien ##########################
function load ($template)
{
$pfad = "template/";
$end = ".tpl";
$this->path = $pfad.$template.$end;
$this->handle = @fopen($this->path,"r");
if (!$this->handle)
{
echo "Konnte Datei <font color="red">($this->path)</font> nicht öffnen";
exit();
}
$this->contents = implode("",file($this->path));
fclose ($this->handle);
}
function replace($search,$replace)
{
$this->contents = str_replace("{$".$search."}", $replace,$this->contents);
}
function get()
{
echo $this->contents;
}
}
############ Für das Parsen von db daten ##########################
function sql_load($table,$where)
{
$this->sql = "SELECT content from ".$table." where name ='".$where."'";
$this->sql_query =mysql_query($this->sql);
while($row = mysql_fetch_object($this->sql_query))
{
$this->content =$row->content;
}
}
function sql_replace ($search,$replace)
{
$this->content = str_replace("{$".$search."}", $replace, $this->content);
}
function sql_get()
{
echo $this->content;
}
?>
mein versuch:
Code: Alles auswählen
function replace_array($search,$replace)
{
if (is_array($replace))
{
foreach ($replace as $key => $value) {
$this->contents = str_replace("{\$".$search."}", $value,$this->contents);
}
}else
{
echo "<font color=\"red\">$replace ist kein array";
}
}
Code: Alles auswählen
$arr = array("eins", "zwei", "drei");