Home > Article > Backend Development > PHP generates html file code_PHP tutorial
There are many ways to generate html file code in php. The more commonly used one is the static method, but what we use below is the php code and method to directly generate pure html file.
There are php code to generate html file. There are many methods, the more commonly used one is the static method, but what we use below is the php code and method that directly generates pure html files. Let’s take a look
The first method: use smary’s template to generate it.
require('smarty/Smarty.class.php');
$t = new Smarty;
$t->assign("title","Hello World!");
$content = $t->fetch("templates/index.htm");
//The fetch() here is the function to get the output content. Now the $content variable contains the content to be displayed
$fp = fopen("archives/2005/05/19/0001.html", "w");
fwrite($fp, $content);
fclose($fp);
?>
Another method is to use php od_get_contents to generate
ob_start();
echo "Hello World!";
$content = ob_get_contents();//Get all the contents output by the php page
$fp = fopen("archives/2005/05/19/0001.html", "w");
fwrite($fp, $content);
fclose($fp);
The third method is to use PHP’s natural function fopen to save directly.