千家信息网

PHP如何生成html文件

发表于:2025-02-03 作者:千家信息网编辑
千家信息网最后更新 2025年02月03日,本篇内容介绍了"PHP如何生成html文件"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!PHP生成h
千家信息网最后更新 2025年02月03日PHP如何生成html文件

本篇内容介绍了"PHP如何生成html文件"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

PHP生成html文件1,下面使用模版的一个方法!

  1. < ?php

  2. $fp = fopen ("templets.html","a");

  3. if ($fp){

  4. $fup = fread ($fp,filesize
    ("templets.html"));

  5. $fp2 = fopen ("html.shtml","w");

  6. if ($fwrite ($fp2,$fup)){

  7. $fclose ($fp);

  8. $fcolse ($fp2);

  9. die ("写入模板成功");

  10. } else {

  11. fclose ($fp);

  12. die ("写入模板失败!");

  13. }

  14. }

  15. ?>

< ?php   $fp = fopen ("templets.html","a");   if ($fp)  { $fup = fread ($fp,filesize("templets.html"));   $fp2 = fopen ("html.shtml","w");   if ($fwrite ($fp2,$fup))  { $fclose ($fp);   $fcolse ($fp2);   die ("写入模板成功"); }   else { fclose ($fp);   die ("写入模板失败!");   }   }   ?>

简单的将模板写进一个文件中存为html.html

PHP生成html文件2,按时间生成html文件名

  1. < ?php

  2. $content = "这是一个以日期时间为文件名
    的静态生成网页的测试文件,文件名格式一
    般为< font color=#ff0000>年月日时分秒
    .html< /font>";

  3. $datedate = date('YmdHis');

  4. $fp = fopen (date('YmdHis') . '.html',"w");
    //本函数可用来打开本地或者远端的文件 'w'
    开文件方式为写入,文件指针指到开始处,
    并将原文件的长度设为 0。若文件不存在,则建立新文件。

  5. if (fwrite ($fp,$content)){
    //格式是.int fwrite(int fp(文件名),
    string string(内容), int [length]
    (长度));本函数将字符串 string 写入文件
    资料流的指针 fp 上。若有指定长度 length,
    则会写入指定长度字符串,或是写到字符串结束。

  6. fclose ($fp);//函数用来关闭已经打开的文
    件的指针 fp。成功返回 true,失败则返回 false。

  7. die ("写入模板成功");

  8. }

  9. else {

  10. fclose ($fp);

  11. die ("写入模板失败!");

  12. }

  13. echo ($content);

  14. ?>

  1. < ?php $content = "这是一个以日期时间为文件名
    的静态生成网页的测试文件,文件名格式一般为

  2. < font color=#ff0000>年月日时分秒.html< /font>";

  3. $datedate = date('YmdHis');

  4. $fp = fopen (date('YmdHis') . '.html',"w");

  5. //本函数可用来打开本地或者远端的文件 'w'
    开文件方式为写入,文件指针指到开始处,
    并将原文件的长度设为 0。若文件不存在,则建立新文件。

  6. if (fwrite ($fp,$content))

  7. {//格式是.int fwrite(int fp(文件名),
    string string(内容), int [length](长度));

  8. 本函数将字符串 string 写入文件资料流的指针 fp 上。
    若有指定长度 length,则会写入指定长度字符串,
    或是写到字符串结束。 fclose ($fp);

  9. //函数用来关闭已经打开的文件的指针 fp。
    成功返回 true,失败则返回 false。

  10. die ("写入模板成功"); }

  11. else { fclose ($fp); die ("写入模板失败!");

  12. }

  13. echo ($content); ?>

PHP生成html文件3,下面为转换文件名的一个方法

< ?php   $s_fname = "93e.php";   $o_fname = "93e.htm";   ob_end_clean();   ob_start();   include($s_fname);   $length = ob_get_length();   $buffer = ob_get_contents();   $buffer = eregi_replace("r","",$buffer);   ob_end_clean();   $fp = fopen($o_fname,"w+");   fwrite($fp,$buffer);   fclose($fp);   ?>
  1. < ?php

  2. $s_fname = "93e.php";

  3. $o_fname = "93e.htm";

  4. ob_end_clean(); ob_start();

  5. include($s_fname);

  6. $length = ob_get_length();

  7. $buffer = ob_get_contents();

  8. $buffer = eregi_replace("r","",$buffer);
    ob_end_clean();

  9. $fp = fopen($o_fname,"w+");
    fwrite($fp,$buffer); fclose($fp);

  10. ?>

"PHP如何生成html文件"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!

0