温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

PHP如何生成html文件

发布时间:2022-04-26 16:25:23 来源:亿速云 阅读:251 作者:iii 栏目:大数据

本篇内容介绍了“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. echo ($content); ?> 

  13.  

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文件”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI