您的位置:首页 > 其它

模版替换技术 生成静态文件

2016-07-18 14:36 239 查看
<?php

  if($_POST){

    //修改操作
$id=$_POST['id'];
$title=$_POST['title'];
$desc=$_POST['desc'];
$filename=$_POST['filename'];

    $pdo=new PDO('mysql:host=localhost;dbname=study7','root','root');

    $pdo->exec("set names utf8");

    $sql="update news set title='$title',content='$desc' where id=$id";
//echo $sql;exit;
$pdo->exec($sql);
//修改后静态页面中的内容要进行改变
$str=file_get_contents('tpl.html');
//把模板中的模板标签进行替换

    $str=str_replace('{$title}',$title,$str);
$str=str_replace('{$desc}',$desc,$str);
//重新写入内容
file_put_contents($filename,$str);
header('location:list.php');

  

  }else{

   //把要修改的数据进行展示

    $id=$_GET['id'];

   $pdo=new PDO('mysql:host=localhost;dbname=study7','root','root');

   $pdo->exec("set names utf8");

   $sql="select * from news where id=$id";

   $row=$pdo->query($sql)->fetch(PDO::FETCH_ASSOC);

    //加载静态模板
include 'update.html';

  }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: