Smarty to realize the two methods of PHP static sharing _linux

Source: Internet
Author: User

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.
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.