这是一个简易的字符串模板引擎、数据库模板引擎。区别于一般基于文件模板的引擎,这里的模板是一个字符串,因此可以将模板存于数据库或其他地方,而且不是编译型引擎,没有缓存文件,因而就不涉及到目录权限问题。模板的基本原理是将模板处理成全php脚本的字符串,然后用eval执行符串。至于安全问题,因为用到eval执行模板里面的语句,因此模板代码必须是受信任的,大多数其他模板引擎也是这样吧。
// 字符串模板,懒得构造字符串,这里直接读取文件来模拟 $str = file_get_contents( 'tpl.php' ); // 首尾添加php脚本标签,使所有原样输出的html文本处于php脚本标签的中间 $str = "<?php if(1){?>{$str}<?php }?>"; // 用echo语句替换原样输出的html文本 $str = preg_replace_callback( '/\?>([\s\S]+?)<\?/', function ($m) { return '?><?php echo "' . addcslashes( $m[1], "\r\n\\\"" ) . '";?><?'; }, $str ); // 去掉php脚本标签并执行标签里面的代码 eval( str_replace( array ( '<?php', '?>' ), '', $str ) );

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Chinese version
Chinese version, very easy to use

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
