Beste mensen,
Ik ben een template systeempje aan het maken. Nu moet ik dus in php documenten nogal eens een lactatie invoeren. Dus ik dacht ik maak een preg_replace functie die bijvoorbeel {T_THEME_PATH} omzet in styles/jouw_stijl/theme.

Ik heb nu een probleem en dat is dat ik niet weet hoe ik preg_replace een gehel pagnina kan laten lezen en ook replacen.

Mijn preg_replace code in mijn function sile ziet er zo iut:
public function replaces($phpDoc)
{
$commonReplaces = array(
"T_THEME_PATH" => "styles/control/theme",
"ROOT_PATH" => $_SERVER['DOCUMENT_ROOT']."/Template/"
);
foreach($commonReplaces as $key => $value)
{
$this->phpDoc = preg_replace('#\{'.$key.'\}#Us',$value,$phpDoc);
}
}

Groetjes,

Daniƫl
Gewoon file_get_contents() erdoorheen halen.
Al geprobeerd. Als ik dat doe dan werkt het of helamaal niet niet of hij geeft de tekst van de pagina en dan nog eens de door de preg_replace beahndelde file_getcontents array weer
Dan zit er een fout in je andere code.
Ik zal niet weten wat voor fout er in zit. Ik jheb mijn cripts nog een paar keer over gekeken en weet van gekkigheid niet meer wat er fout zit :S
Hier ff de scripts

functions.php:
<?php
ini_set( 'display_errors', 1 );
error_reporting( E_ALL | E_STRICT );
class template
{
public $file = '';
public $error = '';
public $getFile = false;
public $html = '';
public $phpDoc = '';
public $parseCSS = '';


public function __construct($file = false)
{
if($file != "" && $file != false)
{
if(!preg_match("/(.+?).html$/si",$file))
{
$this->error = "<b>Parse error:</b> The file has to be a html document!";
}
elseif(!file_exists($file))
{
$this->error = "<b>Parse error:</b> The file ".$file." does not exsist!";
}
$this->file = $file;
}
}
public function getFile()
{
if(file_exists($this->file))
{
$this->html = file_get_contents($this->file);
$this->getFile = true;
}
}

public function replaces($lang,$phpDoc)
{
if($this->getFile == false)
{
$this->getFile();
}
$this->html = preg_replace_callback('#\<\!-- INCLUDE (.+?).html --\>#',
create_function('$matches','return file_get_contents("styles/control/template/".$matches[1].".html");'), $this->html);

foreach($lang as $key => $value)
{
$this->html = preg_replace("#\{L_".$key."\}#s",$value,$this->html);
}
$this->phpDoc = file_get_contents($phpDoc);
$commonReplaces = array(
"ROOT_PATH" => $_SERVER['DOCUMENT_ROOT']."/Template/",
"T_THEME_PATH" => "styles/control/theme"
);
foreach($commonReplaces as $key => $value)
{
$this->phpDoc = preg_replace('#\{'.$key.'\}#Us',$value,$this->phpDoc);
}
}

public function parse()
{
if($this->error == '')
{
if($this->getFile == false)
{
$this->getFile();
}
return $this->html;
}
else
{
return $this->error;
}
}
}
?>


index.php:
<?php

include_once("includes/functions.php");
include("language/nl/common.php");
$nt = new template("styles/control/template/index.html");
$nt->replaces($lang, "index.php");
$nt->parseCSS("styles/control/theme/stylesheet.css");
echo $nt->parse();
include("{T_THEME_PATH}/testfile.php");

?>

Reageren