方法:
$this->assign('style',$style);//变量 $this->display();//模板 <?php /*配制*/ $config=array( /* 数据库设置 */ 'DB_TYPE' => 'mysql', // 数据库类型 'DB_HOST' => 'localhost', // 服务器地址 'DB_NAME' => 'php', // 数据库名 'DB_USER' => 'root', // 用户名 'DB_PWD' => '123', // 密码 'DB_PREFIX' => 'jiaodu_', // 数据库表前缀 'DB_CHARSET' => 'utf8', // 数据库编码默认采用utf8 /* SESSION设置 */ 'SESSION_START' => 'user', //session方式,文件方式:file, 数据库设置为user /* 模板引擎设置 */ 'TMPL_ADMIN_PATH' =>'admin',//后台目录名称 'TMPL_COMPILE_PATH' =>'/Runtime',//读写目录 'TMPL_PATH' =>'/template',//模板路径 'TMPL_TEMPLATE_SUFFIX' => 'html', // 默认模板文件后缀 'TMPL_L_DELIM' => '{', // 模板引擎普通标签开始标记 'TMPL_R_DELIM' => '}', // 模板引擎普通标签结束标记 'TMPL_STRIP_SPACE' => true, // 是否去除模板文件里面的html空格与换行 'TMPL_CACHE_ON' => true, // 是否开启模板编译缓存,设为false则每次都会重新编译,一般用于模板调试 /* URL设置 */ 'URL_HTML_SUFFIX' => 'html', // URL伪静态后缀设置 'URL_PATHINFO_MODEL' => 2, // URL模式,1不隐藏、2隐藏入口文件[需要规则支持] /*其它设置*/ 'PASS_ENCRYPT' =>'www.php.cn',//加密因子 );
[PHP]代码
<?php /** * 模板解析类 * @author 角度 QQ:1286522207 * */ class template extends Action{ private $config; private $CompileDir;//编译目录 private $templateDir;//模板目录 private $templateFile; private $debuy=1;//是否调试 private $assign;//变量 public function __construct($templateFile){ $this->config(); $this->templateFile=$templateFile; } private function config(){ global $config; $this->config=$config; $this->CompileDir=$this->config['TMPL_COMPILE_PATH'].'/Compile'; $this->templateDir=$this->config['TMPL_PATH']; $this->debuy=$this->config['TMPL_CACHE_ON']; } /** * 检查编译目录 */ public function is_CompileDir(){ $dir=APP_PATH.$this->CompileDir; if (!is_dir($dir)){ if (!mkdir($dir)){ die('编译目录自动创建失败,请手动创建'); } } if (!is_writeable($dir)){ die('编译目录没有写入权'); } } /** * 注入变量 */ public function assign($assign) { $this->assign=$assign; } /** * 输出模板 */ public function display(){ $this->is_CompileDir(); $this->CompileCheck(); } /** * 检查编译 */ private function CompileCheck(){ $this->is_CompileDir(); $filename=APP_PATH.$this->CompileDir.'/'.md5($this->templateFile).'.php'; if ($this->debuy || !is_file($filename)){ $this->tmplstrtpspace($filename); } foreach ($this->assign as $key=>$row){ $$key=$row; } include $filename; } /** * 格式化模板并写入编译 */ private function tmplstrtpspace($filename){ if ($this->config['TMPL_STRIP_SPACE']){ $find = array("~>\s+<~","~>(\s+\n|\r)~"); $replace = array("><",">"); $tmplContent = preg_replace($find, $replace,$this->templateCheck()); }else { $tmplContent = $this->templateCheck(); } if (file_put_contents($filename,trim($tmplContent))){ return true; }else { die('编译写入失败'); } } /** * 检查模板 */ private function templateCheck(){ $PATH=APP_PATH.$this->templateDir.'/'.$this->templateFile.'.html'; if (is_file($PATH)){ return $this->template_compile(file_get_contents ( $PATH )); }else { die('模板:'.$this->templateFile.'.html 不存在'); } } /** * 编译模板 */ private function template_compile($template_Conver){ if (empty($template_Conver)){ return $template_Conver; }else { $_Left= $this->config['TMPL_L_DELIM']; $_Right= $this->config['TMPL_R_DELIM']; $template_Preg [] = '/<\?(=|php|)(.+?)\?>/is'; $template_Preg [] = '/' . $_Left . '(else if|elseif) (.*?)' . $_Right . '/i'; $template_Preg [] = '/' . $_Left . 'for (.*?)' . $_Right . '/i'; $template_Preg [] = '/' . $_Left . 'while (.*?)' . $_Right . '/i'; $template_Preg [] = '/' . $_Left . '(loop|foreach) (.*?)' . $_Right . '/i'; $template_Preg [] = '/' . $_Left . 'if (.*?)' . $_Right . '/i'; $template_Preg [] = '/' . $_Left . 'else' . $_Right . '/i'; $template_Preg [] = '/' . $_Left . "(eval|_)( |[\r\n])(.*?)" . $_Right . '/is'; $template_Preg [] = '/' . $_Left . '_e (.*?)' . $_Right . '/is'; $template_Preg [] = '/' . $_Left . '_p (.*?)' . $_Right . '/i'; $template_Preg [] = '/' . $_Left . '\/(if|for|loop|foreach|eval|while)' . $_Right . '/i'; $template_Preg [] = '/' . $_Left . '((( *(\+\+|--) *)*?(([_a-zA-Z][\w]*\(.*?\))|\$((\w+)((\[|\()(\'|")?\$*\w*(\'|")?(\)|\]))*((->)?\$?(\w*)(\((\'|")?(.*?)(\'|")?\)|))){0,})( *\.?[^ \.]*? *)*?){1,})' . $_Right . '/i'; $template_Preg [] = "/( | ){0,}(\r\n){1,}\";/"; $template_Preg [] = '/' . $_Left . '(\#|\*)(.*?)(\#|\*)' . $_Right . '/'; $template_Preg [] = '/' . $_Left . '\%([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)' . $_Right . '/'; $template_Replace [] = '<?\\1\\2?>'; $template_Replace [] = '<?php }else if (\\2){ ?>'; $template_Replace [] = '<?php for (\\1) { ?>'; $template_Replace [] = '<?php while (\\1) { ?>'; $template_Replace [] = '<?php foreach ((array)\\2) { $__i++; ?>'; $template_Replace [] = '<?php if (\\1){ ?>'; $template_Replace [] = '<?php }else{ ?>'; $template_Replace [] = '<?php \\3; ?>'; $template_Replace [] = '<?php echo \\1; ?>'; $template_Replace [] = '<?php print_r(\\1); ?>'; $template_Replace [] = '<?php } ?>'; $template_Replace [] = '<?php echo \\1;?>'; $template_Replace [] = ''; $template_Replace [] = ''; $template_Replace [] = '<?php echo $this->lang_array[\'\\1\'];?>'; return preg_replace ( $template_Preg, $template_Replace, $template_Conver ); } } }

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

在PHP中,可以利用implode()函数的第一个参数来设置没有分隔符,该函数的第一个参数用于规定数组元素之间放置的内容,默认是空字符串,也可将第一个参数设置为空,语法为“implode(数组)”或者“implode("",数组)”。


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

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.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools
