troy1984
11-21-2003, 02:29 AM
I want to know how to use "ereg_replace" in a template class.
These are my files:
Controll Class __________________________________
<?php
include("include/dbclass.php"); // bestanden includeren tot de klasse
include("include/tpclass.php");
class pagina // klasse pagina aanmaken
{
var $id;
var $result = array("" => "");
function pagina () // constructor
{
$db = new database();
$db->uitvoeren("select * from pagina");
while ($row = $db->uitlezen())
{
$user = $row[0];
echo "<a href=\"page.php?id=$row[id]\">$row[achternaam]</a><br>";
}
if(isset($_GET[id]))
{
$this->update();
}
if($_POST[submit] = "opslaan")
{
$this->opslaan();
}
$this->weergeven();
}
function opslaan ()
{
$db = new database();
$db->uitvoeren("update pagina set content='$_POST[content]' where id='$_POST[id]'");
}
function update()
{
$obj_database=new database();
$obj_database->uitvoeren ("select * from pagina where id=$_GET[id]");
$this->result = $obj_database->uitlezen();
}
function weergeven () // functie weergeven aanmaken
{
$obj_template=new template;
$obj_template->inlezen("cms/tpl/pagina.htpl");
$obj_template->vullen($this->result);
$obj_template->tonen();
}
}
$pagina = new pagina ();
?>
_________________________________
Template Class
_________________________________
<?php
class template //klasse template aanmaken
{
var $tpl; //variabel tpl aanmaken
function inlezen($bestand) //functie inlezen aanmaken waarbij het bestand variabel is
{
$fp=fopen($bestand, "r"); //het variabele bestand openen
$this->tpl=fread($fp, filesize ($bestand)); //bestand inlezen
fclose($fp); //bestand sluiten
}
function vullen($varray) //functie vullen aanmaken waarbij varray variabel is
{
foreach($varray as $key => $value)
$this->tpl=str_replace ("<#$key#>", $value, $this->tpl);
} //key aanmaken voor de vervanging met varray
function tonen() //functie tonen aanmaken
{
echo $this->tpl; //weergeven van tpl
}
}
?>
__________________________________
I want to replace: <#Firstname#> <#Lastname#> by "nothing". (A space or something ?...)
Thank you in advance
Greetings,
Troy
These are my files:
Controll Class __________________________________
<?php
include("include/dbclass.php"); // bestanden includeren tot de klasse
include("include/tpclass.php");
class pagina // klasse pagina aanmaken
{
var $id;
var $result = array("" => "");
function pagina () // constructor
{
$db = new database();
$db->uitvoeren("select * from pagina");
while ($row = $db->uitlezen())
{
$user = $row[0];
echo "<a href=\"page.php?id=$row[id]\">$row[achternaam]</a><br>";
}
if(isset($_GET[id]))
{
$this->update();
}
if($_POST[submit] = "opslaan")
{
$this->opslaan();
}
$this->weergeven();
}
function opslaan ()
{
$db = new database();
$db->uitvoeren("update pagina set content='$_POST[content]' where id='$_POST[id]'");
}
function update()
{
$obj_database=new database();
$obj_database->uitvoeren ("select * from pagina where id=$_GET[id]");
$this->result = $obj_database->uitlezen();
}
function weergeven () // functie weergeven aanmaken
{
$obj_template=new template;
$obj_template->inlezen("cms/tpl/pagina.htpl");
$obj_template->vullen($this->result);
$obj_template->tonen();
}
}
$pagina = new pagina ();
?>
_________________________________
Template Class
_________________________________
<?php
class template //klasse template aanmaken
{
var $tpl; //variabel tpl aanmaken
function inlezen($bestand) //functie inlezen aanmaken waarbij het bestand variabel is
{
$fp=fopen($bestand, "r"); //het variabele bestand openen
$this->tpl=fread($fp, filesize ($bestand)); //bestand inlezen
fclose($fp); //bestand sluiten
}
function vullen($varray) //functie vullen aanmaken waarbij varray variabel is
{
foreach($varray as $key => $value)
$this->tpl=str_replace ("<#$key#>", $value, $this->tpl);
} //key aanmaken voor de vervanging met varray
function tonen() //functie tonen aanmaken
{
echo $this->tpl; //weergeven van tpl
}
}
?>
__________________________________
I want to replace: <#Firstname#> <#Lastname#> by "nothing". (A space or something ?...)
Thank you in advance
Greetings,
Troy