zoukankan      html  css  js  c++  java
  • PHP动态页面 生产静态页 方法二

    PHP文件:1.php

    <?php
    header('Content-type: text/html; charset=utf8');
    $title = "这个是标题吗??变量名title";
    $file = "这是什么?这个变量名为file";
    $fp = fopen ("templets/temp.html","r");
    $content = fread ($fp,filesize ("templets/temp.html"));
    $content = str_replace ("{file}",$file,$content);
    $content = str_replace ("{title}",$title,$content);
    
    /* // 生成列表开始
    $list = '';
    $sql = "select id,title,filename from article";
    $query = mysql_query ($sql);
    while ($result = mysql_fetch_array ($query)){
        $list .= '<a href='.$root.$result['filename'].' target=_blank>'.$result['title'].'</a><br>'; }
        $content .= str_replace ("{articletable}",$list,$content); //生成列表结束
        // echo $content; */
    
    $filename = "test/test.html";
    $handle = fopen ($filename,"w"); //打开文件指针,创建文件
    if (!is_writable ($filename)) {
        die ("文件:".$filename."不可写,请检查其属性后重试!");
    }
    if (!fwrite ($handle,$content)){ //将信息写入文件
        die ("生成文件".$filename."失败!");
    }
    fclose ($handle); //关闭指针
    die ("创建文件".$filename."成功!");
    ?>

    模板文件名:templets/temp.html

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    
    </body>
    <table width="500" border="0" cellpadding="5" cellspacing="1" align="center" bgcolor="#add3ef">
      <tr bgcolor="#eff3ff">
        <td>{file}</td>
      </tr>
      <tr bgcolor="#fff">
        <td>{title}</td>
      </tr>
    </table>
    </form>
    </html>
  • 相关阅读:
    设计模式第一次练习
    区间最大数
    魔方数
    螺旋数
    回文串
    最长单词
    指针的应用之学生成绩
    赛马
    突击队任务
    贪婪之骑士
  • 原文地址:https://www.cnblogs.com/xcxc/p/2572681.html
Copyright © 2011-2022 走看看