Chinaunix

标题: [求救]php生成html问题 [打印本页]

作者: yanjing5462    时间: 2005-11-18 16:34
标题: [求救]php生成html问题
test.php文件,用来生成html的
  1. <?php
  2. $title = "拓迈国际测试模板";
  3. $file = "TwoMax Inter test templet,<br/>author:Matrix@Two_Max";
  4. $fp = fopen ("temp.html","r");
  5. $content = fread ($fp,filesize ("temp.html"));
  6. $content .= str_replace ("{file}",$file,$content);
  7. $content .= str_replace ("{title}",$title,$content);

  8. $filename = "test/test.html";
  9. $handle = fopen ($filename,"w"); //打开文件指针,创建文件

  10. if (!is_writable ($filename)){
  11. die ("文件:".$filename."不可写,请检查其属性后重试!");
  12. }
  13. if (!fwrite ($handle,$content)){ //将信息写入文件
  14. die ("生成文件".$filename."失败!");
  15. }
  16. fclose ($handle); //关闭指针
  17. die ("创建文件".$filename."成功!");
  18. ?>
复制代码


模板文件temp.html
  1. <title>{title}</title>
复制代码


运行结果test/test.html源码
  1. <TITLE>{title}</TITLE>
  2. <TITLE>{title}</TITLE>
  3. <TITLE>拓迈国际测试模板</TITLE>
  4. <TITLE>拓迈国际测试模板</TITLE>
复制代码

生成了四个,请大家帮帮忙,看是什么问题,谢谢
作者: HonestQiao    时间: 2005-11-18 16:40
建议使用:
http://w.yi.org/ftp/FAPM/PHP/php ... e-get-contents.html


还有:
http://w.yi.org/ftp/FAPM/PHP/php ... e-put-contents.html
作者: HonestQiao    时间: 2005-11-18 16:41
  1. $content .= str_replace ("{file}",$file,$content);
  2. $content .= str_replace ("{title}",$title,$content);
复制代码


明白.=的意思么?
作者: bandw    时间: 2005-11-18 16:41
原帖由 HonestQiao 于 2005-11-18 16:40 发表
建议使用:
http://w.yi.org/ftp/FAPM/PHP/php ... e-get-contents.html


还有:
http://w.yi.org/ftp/FAPM/PHP/php ... e-put-contents.html

why?
作者: HonestQiao    时间: 2005-11-18 16:44
一次读入文件的所有内容
一次写入所有文件的内容

较之打开,读取/写入,关闭,不是更好么?
作者: yanjing5462    时间: 2005-11-18 17:02
问题解决了,现在想在网站上用php生成html的表现形式,请大家给点建议,用哪种技术好啊,谢谢
作者: devboy    时间: 2005-11-19 03:38
提示: 作者被禁止或删除 内容自动屏蔽




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2