Home  >  Article  >  Backend Development  >  PHP generates html file code_PHP tutorial

PHP generates html file code_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:07:06850browse

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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630487.htmlTechArticleThere are many ways to generate html file code in php. The more commonly used one is the static method, but we The following is the php code and method to directly generate pure html files. php generates html files...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn