Using template file
<html>
<head><title>{title}</title></head>
<body>
<h1>{headline}</h1>
<h2>By {byline}</h2>
{article}
<hr/>
<h4>Page generated: {date}</h4>
</body>
</html>
////////////////////////
<?php
$page = file_get_contents('article.html');
if ($page === false) {
die("Can't read article.html: $php_errormsg");
}
$vars = array('{title}' => 'A',
'{headline}' => 'B',
'{byline}' => 'C',
'{article}' => "<p>D</p>",
'{date}' => date('l, F j, Y'));
foreach ($vars as $field => $new_value) {
$page = str_replace($field, $new_value, $page);
}
$result = file_put_contents('dog-article.html', $page);
if (($result === false) || ($result == -1)) {
die("Couldn't write dog-article.html: $php_errormsg");
}
?>
Related examples in the same category