_php tutorial on how to generate HTML in bulk in Smarty

Source: Internet
Author: User

After some groping, finally found a way to write to everyone pointing out:
First add such a method to the Smarty class in smartt.class.php:
PHP Code:
Parameter one: The HTML file save path, Parameter 2: Write the content
function Makehtmlfile ($file _name, $c)
{
if (! $fp = fopen ($file _name, "WA"))
{
echo "File open failed! ";
return false;
}
if (!fwrite ($FP, $c))
{
echo "File write Failed! ";
Fclose ($FP);
return false;
}
Fclose ($FP);
}


Question: All my articles are called News.tpl this template, then how to batch generation it?

Let's see news.php first.
PHP Code:

Include_once ("config.php");
Include_once ("init.php");
$s->assign ("title", "All News categories");
$ID =$_get["ID"]+0;
$sql = "SELECT * from artical where newsid= $ID";
$rs = $db->fetch ($sql);
$s->assign ("news", $rs ["Rec"][0]);//Note: $rs ["Rec"][0] is a number of groups
$s->display ("news.html");
?>


The whole template variable is only $news, so what's the benefit of writing it? I can read the contents as an array

So how exactly is the build:
Look at the following code:
It's simple.
PHP Code:

Include_once ("config.php");
Include_once ("init.php");
$sql = "SELECT * from artical";
$rs = $db->fetch ($sql);
foreach ($rs ["Rec"] as $k + = $v)
{
$s->assign ("news", $v);
$s->makehtmlfile ("./news/news_". $v [0]. ". HTML ", $s->fetch (" news.html ", NULL, NULL, FALSE));
}
?>


It's a simple move!


PHP Code:




<{$news .titles}>






















<{$news .titles}>
Author: <{$news .author}> Time: <{$news .sj}> Keywords: <{$news .keyword}>
Core tips: <{$news .sumary}>
<{$news .contents}>



Summary: The main use of the Smarty fetch method, and file read and write operations

http://www.bkjia.com/PHPjc/508318.html www.bkjia.com true http://www.bkjia.com/PHPjc/508318.html techarticle after some groping, finally find the method, write to everybody pointing out: First in smartt.class.php to add such a method for the Smarty class: PHP Code://Parameter one: HTML file Save ...

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