Voting

: five plus three?
(Example: nine)

The Note You're Voting On

apmuthu at usa dot net
14 years ago
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;
}

?>

<< Back to user notes page

To Top