首先建立一个conn.PHP的文件用来链接数据库
404_3@ 代码如下:
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");
?>
$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
404_3@ 代码如下:
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 "生成成功"."
";
}
/* 释放资源 */
MysqL_free_result($result);
MysqL_close($link);
?>
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 "生成成功"."
";
}
/* 释放资源 */
MysqL_free_result($result);
MysqL_close($link);
?>
template.html文件内容:
404_3@ 代码如下:
{introduce}
PHP 批量生成txt
404_3@ 代码如下:
PHP
require_once(“conn.PHP”);
$query = "SELECT kid,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,strip_tags($introduce)); //把刚才替换的内容写进生成的txt文件
fclose($handle);
}
/* 释放资源 */
MysqL_free_result($result);
MysqL_close($link);
?>
原文链接:https://www.f2er.com/php/25992.htmlrequire_once(“conn.PHP”);
$query = "SELECT kid,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,strip_tags($introduce)); //把刚才替换的内容写进生成的txt文件
fclose($handle);
}
/* 释放资源 */
MysqL_free_result($result);
MysqL_close($link);
?>