blade模板引擎模仿
来源:互联网 发布:每天目标的软件 编辑:程序博客网 时间:2024/05/22 12:28
blade模板模仿
<?phpclass view{ protected $patternforeach1='/@foreach(\(.*\))/Us'; protected $patternforeach2='/@endforeach/Us'; protected $patternvar='/{(.*)}/Us'; protected $patternfor1='/@for(\(.*\))/Us'; protected $patternfor2='/@endfor/Us'; protected $patternif1='/@if(\(.*\))/Us'; protected $patternif2='/@endif/Us'; protected $patternelse1='/@elseif(\(.*\))/Us'; protected $patternelse2='/@else/Us'; public function compile($file) { foreach(func_get_args() as $key=>$value) { if($key>0){ foreach($GLOBALS as $k=>$v) { if($value===$v) { $$k=$v; } } } } //开始编辑 $str=file_get_contents($file.'.blade.php'); $str=$this->elses($this->ifs($this->fors($this->foreachs($this->vars($str))))); file_put_contents('./com'.$file.'balde.php',$str); include './com'.$file.'balde.php'; } public function vars($str) { $str=preg_replace($this->patternvar,"<?php echo ".'$1'." ;?>",$str); return $str; } public function foreachs($str) { $str=preg_replace($this->patternforeach1,"<?php foreach".'$1'."{ ?>",$str); $str=preg_replace($this->patternforeach2,"<?php } ?>",$str); return $str; } public function fors($str) { $str=preg_replace($this->patternfor1,"<?php for".'$1'."{ ?>",$str); $str=preg_replace($this->patternfor2,"<?php } ?>",$str); return $str; } public function ifs($str) { $str=preg_replace($this->patternif1,"<?php if".'$1'."{ ?>",$str); $str=preg_replace($this->patternif2,"<?php } ?>",$str); return $str; } public function elses($str) { $str=preg_replace($this->patternelse1,"<?php }elseif".'$1'."{ ?>",$str); $str=preg_replace($this->patternelse2,"<?php }else{ ?>",$str); return $str; }}$view=new view();$number=range(1,26);$names=range('a','z');$names=array_combine($number,$names);$name='请选择';$i=54;$j=45;$view->compile('ok',$names,$name,$i,$j);
html
<!DOCTYPE HTML><html><head><meta charset="utf-8"><title>TEST</title></heade><body>单变量解析 {$name}<hr>foreach镶嵌if解析 <select> @foreach($names as $key=>$value)<option value="{$key}" @if($key===5) selected='selected' @endif >{$value}</option> @endforeach </select> <hr> for 镶嵌if解析 <select> @for($k=0;$k<=100;$k++)<option value="{$k}" @if($k===5) selected='selected' @endif >{$k}</option> @endfor </select> <hr> if else结构解析 @if($i<$j) $i<$j @elseif($i==$j) $i=$j @elseif($i>$j) $i>$j @endif <hr> 多层镶嵌解析 <ul> @foreach($names as $key=>$value) <li>{$value} <ul> @for($l=0;$l<100;$l++) <li>{$l} <ul> @for($c=0;$c<20;$c++) <li> @if($c==10) <span style='color:red'>{$c}</span> @else {$c} @endif </li> @endfor </ul> </li> @endfor </ul> <li> @endforeach <ul><!--/请在上方写此页面业务相关的脚本--></body></html>
阅读全文
0 0
- blade模板引擎模仿
- Blade模板引擎
- 13. Blade 模板引擎
- Laravel-Blade模板引擎
- Laravel Blade模板引擎
- laravel Blade 模板引擎 命令
- Laravel之Blade模板引擎
- Laravel之Blade模板引擎
- Blade模板引擎-常用语法格式
- Laravel-Blade模板引擎-3.流程控制
- Laravel基础-Blade模板引擎流程控制
- Blade模板引擎教程-常用语法格式
- Laravel中Blade模板引擎用法
- Laravel中Blade模板引擎流程控制
- Laravel中Blade模板引擎子视图
- Laravel入门教程(六)- Blade模板引擎
- Laravel中的模板引擎——Blade
- Laravel-Blade模板引擎-4. 模板中的URL
- 【51Nod1711】平均数
- 官网下载Spring的jar教程
- –定义一个圆类(Circle),其所在的包为bzu.info.software;定义一个圆柱类Cylinder,其所在的包为bzu.info.com;定义一个主类A,其所在的包也为bzu.info.
- 坑爹的 socket /com/ubuntu/upstart: 拒绝连接
- ionic3常用命令行集合
- blade模板引擎模仿
- Spring Boot中支持i18n简明教程
- ConstraintLayout的学习使用
- 性能测试常用工具
- Handler简介以及一个使用简例
- 搭建kafka
- ZonedDateTime工具类
- 浏览器先渲染图片后渲染文字
- surface 无法启动,无限重启解决方案,UEFI