note 98511 added to function.str-replace
| From: | apmuthu at usa dot net | Date: | Sat, 19 Jun 2010 19:31:34 +0000 |
| Subject: | note 98511 added to function.str-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-170316@lists.php.net to get a copy of this message | ||
If we have a html template that contains placeholders in curly braces that need to be replaced in
runtime, the following function will do it using str_replace:
<?php
function parse_template($filename, $data) {
// example template variables {a} and {bc}
// example $data array
// $data = Array("a" => 'one', "bc" => 'two');
$q = file_get_contents($filename);
foreach ($data as $key => $value) {
$q = str_replace('{'.$key.'}', $value, $q);
}
return $q;
}
?>
----
Server IP: 59.162.86.8
Probable Submitter: 122.164.219.25
----
Manual Page -- http://www.php.net/manual/en/function.str-replace.php
Edit -- https://master.php.net/note/edit/98511
Del: integrated -- https://master.php.net/note/delete/98511/integrated
Del: useless -- https://master.php.net/note/delete/98511/useless
Del: bad code -- https://master.php.net/note/delete/98511/bad+code
Del: spam -- https://master.php.net/note/delete/98511/spam
Del: non-english -- https://master.php.net/note/delete/98511/non-english
Del: in docs -- https://master.php.net/note/delete/98511/in+docs
Del: other reasons-- https://master.php.net/note/delete/98511
Reject -- https://master.php.net/note/reject/98511
Search -- https://master.php.net/manage/user-notes.php