Pain 全世界最小最简单的PHP模板引擎 (普通版)
发布时间:2023-11-18 09:12:06
标签:模板引擎
打包下载
Pain.php
<?php
class Pain
{
public $var=array();
public $tpl=array();
//this is the method to assign vars to the template
public function assign($variable,$value=null)
{
$this->var[$variable]=$value;
}
public function display($template_name,$return_string=false)
{
//first find whether the tmp file in tmp dir exists.
if(file_exists("tmp/temp_file.php"))
{
unlink("tmp/temp_file.php");
}
extract($this->var);
$tpl_content=file_get_contents($template_name);
$tpl_content=str_replace("{@", "<?php echo ", $tpl_content);
$tpl_content=str_replace("@}", " ?>", $tpl_content);
//create a file in the /tmp dir and put the $tpl_contentn into it, then
//use 'include' method to load it!
$tmp_file_name="temp_file.php";
//$tmp is the handler
$tmp=fopen("tmp/".$tmp_file_name, "w");
fwrite($tmp, $tpl_content);
include "tmp/".$tmp_file_name;
}
}
?>
test.php
<?php
require_once "Pain.php";
$pain=new Pain();
$songyu="songyu nb";
$zhangyuan="zhangyuan sb";
$pain->assign("songyu",$songyu);
$pain->assign("zhangyuan",$zhangyuan);
$pain->display("new_file.html");
?>
new_file.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>new_file</title>
</head>
<body>
{@$songyu@}<br/>
{@$zhangyuan@}
</body>
</html>


猜你喜欢
- 数据库中有张表User,字段是ID和Name,ID自增。 利用存储过程实现插入时返回当前的行数 CREATE PROC Proc_Inser
- 接上篇Mysql数据库性能优化二对表进行水平划分 &nbs
- 我就废话不多说了,大家还是直接看代码吧!绘制曲线:import timeimport numpy as npimport matplotli
- 如下所示:3σ 原则(u-3*σ ,u+3*σ )离差标准化(x-min)/(max-min)标准差标准化(x-u)/σ小数定标标准化x/1
- @property作用:python的@property是python的一种装饰器,是用来修饰方法的。我们可以使用@property装饰器来
- 先给大家巩固tempdb的基础知识简介:tempdb是SQLServer的系统数据库一直都是SQLServer的重要组成部分,用来存储临时对
- 一空间多域名绑定3种方法,HTML代码格式:<html> <script language=javascript
- 起步这是许多开发者在项目初期要面临的一个普遍问题。要怎样来处理多用户类型。本文讲介绍对于不同场景和业务需求如何设计用户模型。为项目提供指导设
- 本文实例讲述了Python 25行代码实现的RSA算法。分享给大家供大家参考,具体如下:网络上很多关于RSA算法的原理介绍,但是翻来翻去就是
- 前言首先声明,本工具仅仅为学习之用,不涉及版权问题,因为百度音乐里面的歌曲本身是可以下载的,而且现在百度也提供了”百度音乐播放器”,可以通过
- 下载GPL版本安装MySQL Community Edition(GPL)Community (GPL) Downloads &ra
- Vignere密码Vignere Cipher包含用于加密和解密的Caesar Cipher算法. Vignere Cipher与Caesa
- DDPDistributed Data Parallel 简称 DDP,是 PyTorch 框架下一种适用于单机多卡、多机多卡任务的数据并行
- 问题背景VSCode是我们开发go程序的常用工具,但是安装VSCode成功后,创建一个.go文件会有如下提示:这个是vscode提示你需要安
- 1,flask中内置的过滤器模板中常用方法:{#过滤器调用方式{{变量|过滤器名称}} #} <!-- safe过滤器,可
- 当单台MYSQL服务器无法满足当前网站流量时的优化方案。需要搭建mysql集群技术。一、功能:当向主服务器插入|修改|删除数据时,数据会自动
- MySQL语句优化的基本原则:◆1、使用索引来更快地遍历表。缺省情况下建立的索引是非群集索引,但有时它并不是最佳的。在非群集索引下,数据在物
- 包括安装时提示有挂起的操作、收缩数据库、压缩数据库、转移数据库给新用户以已存在用户权限、检查备份集、修复数据库等。 (一)挂起操作在安装S
- 开发环境说明:Python 35Pytorch 0.2CPU/GPU均可1、LSTM简介人类在进行学习时,往往不总是零开始,学习物理你会有数
- 本文实例讲述了Python数据结构与算法之图的广度优先与深度优先搜索算法。分享给大家供大家参考,具体如下:根据 * 的伪代码实现:广度优先