You can do it using any existing template engines or by the following code set.
Create a template file as shown below ( Tweak the HTML , add more template variables or anything ). Save this to a file and call it mytemplate.txt
<html>
<head>
<title>{title}</title>
</head>
<body>
<h1>{header}</h1>
{text}
</body>
</html>
Create a PHP file , and call it home.php ( Or any name depending on your use case ) . Add the following code.
<?php
$tags['title']="Replaces title tag";
$tags['header']="Replaces header tag";
$tags['text']="Replaces text tag";
//lets us open your template file and replace the tags
print preg_replace("/\{([^\{]{1,100}?)\}/e","$tags[$1]",file_get_contents("mytemplate.txt"));
?>
Make sure that mytemplate.txt, and home.php are in the same directory on your server.
Note :- This gives you a basic template engine, using preg_replace function of PHP.
Here are the references
- https://www.webmasterworld.com/php/3444822.htm
- http://php.net/manual/en/function.preg-replace.php