模版替换技术 生成静态文件
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';
}
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';
}
相关文章推荐
- java基础第二天
- 浅谈兼容性测试
- codeforces C. Lorenzo Von Matterhorn
- 方法
- win下GIT GUI的使用教程
- 【C语言入门教程】1.3 C语言“32个”关键字
- c# 网络
- web05-CounterServlet
- Redis 3.0集群 Window搭建方案
- 欢迎使用CSDN-markdown编辑器
- 各种开源协议
- Effective Java 学习笔记(二)
- java NIO详解
- 苹果开发者证书
- 设计模式之迭代器模式
- Git--远程仓库操作
- 三子棋
- php mysql in array
- visual studio cmakelists
- 自定义元素属性,以及用jquery 去获取当前点击的元素的这个自定义属性