Rumah  >  Artikel  >  pembangunan bahagian belakang  >  php生成html文件代码_PHP教程

php生成html文件代码_PHP教程

WBOY
WBOYasal
2016-07-13 17:07:06817semak imbas

php生成html文件代码有很多种方法,比较常用的一种是为静态的使用方法,但我们下面使用的是直接生成纯html文件的php代码与方法

 php生成html文件代码有很多种方法,比较常用的一种是为静态的使用方法,但我们下面使用的是直接生成纯html文件的php代码与方法,下面我们来看看

第一种方法:就是用smary的模板来生成.

require('smarty/Smarty.class.php');
$t = new Smarty;
$t->assign("title","Hello World!");
$content = $t->fetch("templates/index.htm");
//这里的 fetch() 就是获取输出内容的函数,现在$content变量里面,就是要显示的内容了
$fp = fopen("archives/2005/05/19/0001.html", "w");
fwrite($fp, $content);
fclose($fp);
?>

另一种方法是用php od_get_contents来生成
ob_start();
echo "Hello World!";
$content = ob_get_contents();//取得php页面输出的全部内容
$fp = fopen("archives/2005/05/19/0001.html", "w");
fwrite($fp, $content);
fclose($fp);

 第三种方法就是用php自然的函数fopen来直接保存.

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/630487.htmlTechArticlephp生成html文件代码有很多种方法,比较常用的一种是为静态的使用方法,但我们下面使用的是直接生成纯html文件的php代码与方法 php生成html文...
Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn