天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

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文件的實現代碼,轉載需保留來源!

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

主站蜘蛛池模板: 色播播影院| 成人在线视频免费看 | 国产高清国内精品福利色噜噜 | 精品极品三大极久久久久 | 国产精品成人免费观看 | 91热久久免费频精品99欧美 | 把极品白丝老师啪到腿软 | 欧美不卡一区二区三区 | 国产午夜免费视频片夜色 | 一本色道久久综合亚洲AV蜜桃 | 奶头从情趣内衣下露了出来AV | 轻点灬大ji巴太粗太双性高h | av无码在线日本天堂 | 毛片手机在线观看 | 亚洲成人免费观看 | 大乳牛奶女在线观看 | 色婷婷综合激情中文在线 | 欧美黑白配性xxxxx | 久久国产综合精品欧美 | 玩50岁四川熟女大白屁股直播 | 秘密教学93话恩爱久等了免费 | 佐山爱痴汉theav | 久久无码av三级 | 视频一区亚洲中文字幕 | 午夜DV内射一区二区 | 女性私密五月天 | 1973性农场未删减版 | 亚洲男人97色综合久久久 | 野花日本手机观看大全免费3 | 久久成人精品免费播放 | 青柠在线电影高清免费观看 | 久久毛片免费看一区二区三区 | av狼新人开放注册区 | 欧美性猛交AAA片免费观看 | 征服丝袜旗袍人妻 | 在线不卡日本v二区 | 真人裸交有声性动态图 | 调教女M屁股撅虐调教 | 欧美gv明星 | 蜜桃成熟时2电影免费观看d | 日本无码毛片久久久九色综合 |