首先建立一個conn
<?php
$link = mysql_connect("mysql_host"
mysql_query("set names utf
mysql_select_db("my_database") or die("Could not select database");
?>
php 批量生成html
<?php
require_once(“conn
$query = "SELECT id
$result = mysql_query($query) or die("Query failed : "
/* 生成 HTML 結果 */
while ($row = mysql_fetch_array($result
$id=$row[
$title=$row[
$introduce=$row[
$path="html/$id
$fp=fopen("template
$str=fread($fp
$str=str_replace("{title}"
$str=str_replace("{introduce}"
fclose($fp);
$handle=fopen($path
fwrite($handle
fclose($handle);
//echo "<a href=html/$id
}
/* 釋放資源 */
mysql_free_result($result);
mysql_close($link);
?>
template
<!DOCTYPE html PUBLIC "
<html xmlns="
<head>
<meta http
<title>{title}</title>
</head>
<body>
{introduce}
</body>
</html>
php 批量生成txt
<?php
require_once(“conn
$query = "SELECT kid
$result = mysql_query($query) or die("Query failed : "
/* 生成 txt 結果 */
while ($row = mysql_fetch_array($result
$id=$row[
$title=$row[
$introduce=$row[
$path="html/$id
$handle=fopen($path
fwrite($handle
fclose($handle);
}
/* 釋放資源 */
mysql_free_result($result);
mysql_close($link);
?>
From:http://tw.wingwit.com/Article/program/PHP/201311/20863.html