Forum Moderators: coopster
$name='John';
print("name is $name"); $template = 'You need $flower';
$flower = 'rose';
more_fancy_print($template); $flower='rose';
$name='Greg';
// fetch '$name holds a $flower' into $template
print($template);
// fetch '$flower lies on the table' into $template
print($template); Greg holds a rose
rose lies on the table print("$name holds a $flower"); $template = array(
'{NAME} holds a {FLOWER}',
'{FLOWER} lies on the table'
);
$name = 'Greg';
$flower = 'rose';
$output = '';
foreach($template as $temp) {
$temp = preg_replace('/{NAME}/m', $name, $temp);
$temp = preg_replace('/{FLOWER}/m', $flower, $temp);
$output = ucfirst($temp);
echo '<p>' . $output . '</p>';
}