First create a conn.php file to link the database
<?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 Bulk HTML generation
<?php
Require_once ("conn.php");
$query = "Select Id,title,introduce from my_table";
$result = mysql_query ($query) or Die ("Query failed:". Mysql_error ());
/* Generate HTML Results */
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"); Read-only open template
$str =fread ($fp, FileSize ("template.html"));//Read the contents of the template
$str =str_replace ("{title}", $title, $STR);
$str =str_replace ("{Introduce}", $introduce, $STR);//replace content
Fclose ($FP);
$handle =fopen ($path, "w"); Write to open News path
Fwrite ($handle, Strip_tags ($introduce)); Write the content you just replaced into the generated HTML file
Fclose ($handle);
echo "<a href=html/$id .html> Build Success </a>". <br> ";
}
/* Release Resources */
Mysql_free_result ($result);
Mysql_close ($link);
?>
template.html File Contents:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title>{title}</title>
<body>
{Introduce}
</body>
PHP Batch Generation txt
<?php
Require_once ("conn.php");
$query = "Select Kid,title,introduce from Pro_courses";
$result = mysql_query ($query) or Die ("Query failed:". Mysql_error ());
/* Generate TXT results */
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"); Write to open News path
Fwrite ($handle, Strip_tags ($introduce)); Write the content you just replaced into the generated TXT file
Fclose ($handle);
}
/* Release Resources */
Mysql_free_result ($result);
Mysql_close ($link);
?>
PHP batch generated HTML, TXT file