Home > php教程 > php手册 > PHP如何用Smarty实现html静态化页面

PHP如何用Smarty实现html静态化页面

WBOY
Release: 2016-06-06 19:56:44
Original
1268 people have browsed it

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 PHP如何用Smarty实现HTML静态化页面?以下是具体代码,具体如下: ?php require_once(“./config/config.php”); ob_start(); $id=$_GET[id]; $sql=“select * from table_name where id='$id‘”; $res

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

    PHP如何用Smarty实现HTML静态化页面?以下是具体代码,具体如下:

   

    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);

    // 文件生成函数

    function tohtmlfile_cjjer($file_cjjer_name,$file_cjjer_content){

    if (is_file ($file_cjjer_name)){

    @unlink ($file_cjjer_name); //存在,就删除

    }

    $cjjer_handle = fopen ($file_cjjer_name,“w”); //创建文件

    if (!is_writable ($file_cjjer_name)){ //判断写权限

    return false;

    }

    if (!fwrite ($cjjer_handle,$file_cjjer_content)){

    return false;

    }

    fclose ($cjjer_handle); //关闭指针

    return $file_cjjer_name; //返回文件名

    }

    ?>

    最后在将生成的静态页面发布到web上.

PHP如何用Smarty实现html静态化页面

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template