note 49033 added to function.str-replace

From: Date: Fri, 14 Jan 2005 19:17:35 +0000
Subject: note 49033 added to function.str-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-83284@lists.php.net to get a copy of this message
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'); ?> ---- Manual Page -- http://www.php.net/manual/en/function.str-replace.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+49033 Delete -- http://master.php.net/manage/user-notes.php?action=delete+49033&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49033&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+49033&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+49033&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+49033&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+49033&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+49033&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#83284) next »