欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

PHP读写文件生成HTML的代码举例

程序员文章站 2024-01-24 21:54:46
...
  1. //生成HTML
  2. $countfile="template.html";
  3. $num=file_get_contents($countfile);
  4. echo $num;
  5. $num=str_replace("|*|*|PAGE_TITLE|*|*|","myhome",$num);
  6. $path="template.html";
  7. $handle=fopen($path,"w"); //写入方式打开新闻路径
  8. fwrite($handle,$num); //把刚才替换的内容写进生成的HTML文件
  9. fclose($handle);
  10. ?>
复制代码

说明: file_get_contents -- 将整个文件读入一个字符串 file -- 把整个文件读入一个数组中

详细参考: php file_get_contents抓取页面信息的代码 php file_get_contents函数抓取页面信息的代码 php file_get_contents函数代理获取远程页面的代码 php file_get_contents函数的使用问题