php batch generated html txt file implementation code
- 2020-06-23 00:00:03
- OfStack
First, create an ES0en.php file to link to the database
php generates html in batch
template. html
php generates txt in batch
<?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 generates html in batch
<?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 The results of */
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);// Alternative content
fclose($fp);
$handle=fopen($path,"w"); // Write mode opens the news path
fwrite($handle,strip_tags($introduce)); // I'm just going to put what I just replaced into the generated HTML file
fclose($handle);
//echo "<a href=html/$id.html> Generate success </a>"."<br>";
}
/* Release resources */
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 generates txt in batch
<?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 The results of */
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 mode opens the news path
fwrite($handle,strip_tags($introduce)); // I'm just going to put what I just replaced into the generated txt file
fclose($handle);
}
/* Release resources */
mysql_free_result($result);
mysql_close($link);
?>