mysql_free_result(
$result
);
mysql_close(
$link
);
?>
template.html 文件内容:
代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<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
);
?>