note 49033 deleted from function.str-replace by nlopess

From: Date: Sun, 16 Jan 2005 10:14:36 +0000
Subject: note 49033 deleted from function.str-replace by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-83404@lists.php.net to get a copy of this message
Note Submitter: c dot k at radiogong dot com ---- I wrote a simple Template parser class to show how to use the str_replace function: <?php class parser{ //This is the class var $data; function pub(){ global $index; $file = $this->data; $dat = implode('', file($file)); foreach($index as $key => $value) $datinhalt=str_replace('{'.$key.'}',$value,$datinhalt); echo $dat; } } function output($dat) { // This function makes the using of this script easier $parser = new parser; $parser->datei = $dat; $parser->pub(); } ?> You can use the parser this way: <?php require('parser.php'); $index=array( 'title' => 'Welcome' , 'body' => 'This is the body'); output('Template.htm'); ?>

« previous php.notes (#83404) next »