一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

php 批量生成html,txt文件的實現代碼

首先建立一個conn.php的文件用來鏈接數據庫
復制代碼 代碼如下:
<?php
    $link = mysql_connect("mysql_host" , "mysql_user" , "mysql_password" )or die("Could not connect : " . mysql_error());
    mysql_query("set names utf8");
    mysql_select_db("my_database") or die("Could not select database");
?>

php 批量生成html
復制代碼 代碼如下:
<?php
    require_once(“conn.php”);
    $query = "SELECT id,title,introduce FROM my_table";
    $result = mysql_query($query) or die("Query failed : " . mysql_error());
    /* 生成 HTML 結果 */
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

        $id=$row['id'];
        $title=$row['title'];
        $introduce=$row['introduce'];
        $path="html/$id.html";
        $fp=fopen("template.html","r"); //只讀打開模板
        $str=fread($fp,filesize("template.html"));//讀取模板中內容
        $str=str_replace("{title}",$title,$str);
        $str=str_replace("{introduce}",$introduce,$str);//替換內容
        fclose($fp);
        $handle=fopen($path,"w"); //寫入方式打開新聞路徑
        fwrite($handle,strip_tags($introduce)); //把剛才替換的內容寫進生成的HTML文件
        fclose($handle);
        //echo "<a href=html/$id.html>生成成功</a>"."<br>";
    }
    /* 釋放資源 */
    mysql_free_result($result);
    mysql_close($link);
?>

template.html文件內容:
復制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>{title}</title>
</head>
<body>
{introduce}
</body>
</html>

php 批量生成txt
復制代碼 代碼如下:
<?php
    require_once(“conn.php”);
    $query = "SELECT kid,title,introduce FROM pro_courses";
    $result = mysql_query($query) or die("Query failed : " . mysql_error());
    /* 生成 txt 結果 */
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

        $id=$row['id'];
        $title=$row['title'];
        $introduce=$row['introduce'];
        $path="html/$id.txt";
        $handle=fopen($path,"w"); //寫入方式打開新聞路徑
        fwrite($handle,strip_tags($introduce)); //把剛才替換的內容寫進生成的txt文件
        fclose($handle);
    }
    /* 釋放資源 */
    mysql_free_result($result);
    mysql_close($link);
?>

php技術php 批量生成html,txt文件的實現代碼,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 成人在线视频国产 | 在线一区免费视频播放 | 99在线视频免费观看 | 国产中文字幕一区 | 色xxxxx | 日本久久免费大片 | 国产在线91观看免费观看 | 成年ssswww网站 | 日本精品久久久一区二区三区 | 国产亚洲第一页 | 亚洲精品人成网在线播放影院 | 精品免费在线视频 | 国产精品久久久久久永久牛牛 | 欧美日韩加勒比一区二区三区 | 在线观看一区二区三区四区 | 国产精品久久久久久永久牛牛 | 成人在线视频网 | 午夜在线免费观看视频 | 伊人中文字幕在线观看 | 国产精品成人嫩妇 | 开心久久激情 | 欧美一区二区三区激情啪啪 | 一本色道久久88亚洲精品综合 | 91精品国产免费久久久久久 | 欧美激情不卡 | 国产a级精品特黄毛片 | 一级毛片成人午夜 | 日韩毛片免费视频一级特黄 | 国产91色| 综合久久五月天 | 亚洲五月激情综合图片区 | 亚洲人成综合 | 精品国产美女福利在线 | 成人久久免费视频 | 成人国产精品视频 | 久久久久久综合 | 欧美婷婷色 | 五月天婷婷一区二区三区久久 | 97精品在线播放 | 人人干97 | 国产69成人免费视频观看 |