当前位置: 移动技术网 > IT编程>开发语言>PHP > PHP fopen和fwrite函数实现创建html页面

PHP fopen和fwrite函数实现创建html页面

2019年06月19日  | 移动技术网IT编程  | 我要评论

黑脸女婿,忙噶,手机电影网站下载

思路

用fopen函数和fread函数得到模板,然后用str_replace函数替换模板标签为变量,最后用fwrite函数输出新的html页面

模板页面

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" ""> <html xmlns=""> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>{title}</title> </head>  <body> 文章内容为:{content}  </body> </html> index.php

<?  header('content-type:text/html; charset=utf-8');  $conn=mysql_connect('localhost','root','');  $db=mysql_select_db('bbs',$conn);  mysql_query('set names utf8');  $sql="select * from notice";  $query=mysql_query($sql);   //print_r($arr);  while($arr=mysql_fetch_array($query))   {       $title=$arr[title];       $content=$arr[content];       $file="";       $neirong=$arr[id].".html";  $fp=fopen($file,'r');  $ht=fread($fp,filesize($file));  $str=str_replace('{title}',$title,$ht);  $str=str_replace('{content}',$content,$str);  fclose($file);  $file=fopen($neirong,'w');  $write=fwrite($file,$str);   }   ?> 

 

作者“php学习笔记”

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网