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

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

主站蜘蛛池模板: 国产亚洲精品久久久无码狼牙套 | 男人国产AV天堂WWW麻豆 | 日韩av国产av欧美天堂社区 | 精品国产高清自在线看 | 国产精品一区二区三区免费 | 毛片网站在线观看 | 成人a毛片久久免费播放 | 一区二区三区国产 | 亚洲欧洲日本无在线码播放 | 总裁呻吟双腿大开男男H | 麻豆第一区MV免费观看网站 | 麻生希第一部快播 | 嫩草影院成人 | 十大禁止安装的黄台有风险 | adc高清在线观看 | 夜里18款禁用的免费B站动漫 | 黄色网址在线免费观看 | 狠狠色狠狠色综合日日小说 | 久久精品国产视频澳门 | 午夜特级毛片 | 粗壮挺进邻居人妻无码 | jiizzyou欧美喷液| 国产又粗又猛又爽黄老大爷 | 久久re这里精品23 | 蜜芽最新域名解析网站 | 97碰成视频免费 | 亚洲 日本 天堂 国产 在线 | 搡女人免费免费视频观看 | 99精品中文字幕在线观看 | 国产精品-区区久久久狼 | 少妇被阴内射XXXB少妇BB | 久久99精品AV99果冻 | 忘忧草秋观看未满十八 | 出差无套内射小秘书 | 在线中文字幕视频 | 贵妇局长的蕾丝乳罩 | 欧美一区二区三区不卡免费 | 国产不卡一卡2卡三卡4卡网站 | 噜噜噜狠狠夜夜躁 | 久久综合狠狠综合久久综合88 | 免费观看成人www精品视频在线 |