Method One:
Copy Code code as follows:
<?php
Require_once ("./config/config.php");
Ob_start ();
$id =$_get[id];
$sql = "SELECT * FROM table_name where id= ' $id '";
$result =mysql_query ($sql);
$rs =mysql_fetch_object ($result);
$smarty->assign ("Showtitle", $rs->title);
$smarty->assign ("Showcontent", $rs->content);
$smarty->display ("content.html");
$this _my_f= ob_get_contents ();
Ob_end_clean ();
$filename = "$id. html";
Tohtmlfile_cjjer ($filename, $this _my_f);
File generation functions
function Tohtmlfile_cjjer ($file _cjjer_name, $file _cjjer_content) {
if (Is_file ($file _cjjer_name)) {
@unlink ($file _cjjer_name); exists, you delete
}
$cjjer _handle = fopen ($file _cjjer_name, "w"); Create a file
if (!is_writable ($file _cjjer_name)) {//Judge Write permission
return false;
}
if (!fwrite ($cjjer _handle, $file _cjjer_content)) {
return false;
}
Fclose ($cjjer _handle); Close pointer
return $file _cjjer_name; Return file name
}
?>
Method Two:
Smarty has a way to get Template page content method Fetch (), its declaration prototype is this:
Copy Code code as follows:
<?php
function fetch ($resource _name, $cache _id = null,
$compile _id = null, $display = False)
?>
The first parameter is the template name, the second parameter is the cached ID, the third parameter is the compilation ID, and the fourth parameter is whether the template content is displayed. We need to use this method to generate a static page.
Copy Code code as follows:
<?php
$smarty = new Smarty ();
Other template substitution syntax ...
The following sentence gets all the contents of the page, noting that the last argument is False
$content = $smarty->fetch (' template name. TPL ', NULL, NULL, FALSE);
The following writes the content to a static file
$fp = fopen (' news.html ', ' W ');
Fwrite ($fp, $content);
Fclose ($FP);
OK, here's the news.html static page, and you can take care of your next job.
?>