很多站长朋友们都不太清楚自己写的php模板引擎,今天小编就来给大家整理自己写的php模板引擎,希望对各位有所帮助,具体内容如下:
本文目录一览: 1、 有没有谁写过自己的php模板引擎或者框架? 2、 php 模板引擎有什么好?本想自己写一个模板引擎,融合到自己设计的框架中去(现在使用类似 word 3、 PHP 模板引擎的简单代码怎么弄! 有没有谁写过自己的php模板引擎或者框架?我写过一个模板引擎,思想和正则表达式大部分来源于康盛uchome。
php 模板引擎有什么好?本想自己写一个模板引擎,融合到自己设计的框架中去(现在使用类似 word推荐使用thinkphp框架,使用wp框架其实并不需要include包含了,可以把自定义代码全部写到functions.php里或做个插件
PHP 模板引擎的简单代码怎么弄!//phpcms 的核心模板解析函数
/*
*/
function template_parse($str)
{
$str = preg_replace("/\{(\\$[a-zA-Z0-9_\[\]\'\"\$\x7f-\xff]+)\}/es", "addquote('<?php echo \\1;?>')",$str);
$str = preg_replace("/\{([A-Z_\x7f-\xff][A-Z0-9_\x7f-\xff]*)\}/s", "<?php echo \\1;?>",$str);
$str = preg_replace("/([\n\r]+)\t+/s","\\1",$str);
$str = preg_replace("/\<\!\-\-\{(.+?)\}\-\-\>/s", "{\\1}",$str);
$str = preg_replace("/\{template\s+(.+)\}/","\n<?php include template(\\1); ?>\n",$str);
$str = preg_replace("/\{include\s+(.+)\}/","\n<?php include \\1; ?>\n",$str);
$str = preg_replace("/\{php\s+(.+)\}/","\n<?php \\1?>\n",$str);
$str = preg_replace("/\{if\s+(.+?)\}/","<?php if(\\1) { ?>",$str);
$str = preg_replace("/\{else\}/","<?php } else { ?>",$str);
$str = preg_replace("/\{elseif\s+(.+?)\}/","<?php } elseif (\\1) { ?>",$str);
$str = preg_replace("/\{\/if\}/","<?php } ?>",$str);
$str = preg_replace("/\{loop\s+(\S+)\s+(\S+)\}/","<?php if(is_array(\\1)) foreach(\\1 AS \\2) { ?>",$str);
$str = preg_replace("/\{loop\s+(\S+)\s+(\S+)\s+(\S+)\}/","\n<?php if(is_array(\\1)) foreach(\\1 AS \\2 => \\3) { ?>",$str);
$str = preg_replace("/\{\/loop\}/","\n<?php } ?>\n",$str);
$str = preg_replace("/\{tag_([^}]+)\}/e", "get_tag('\\1')", $str);
$str = preg_replace("/\{\\$([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*\(([^{}]*)\))\}/","<?php echo \\1;?>",$str);
$str = preg_replace("/\{(\\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\}/","<?php echo \\1;?>",$str);
}
function addquote($var)
{
return str_replace("\\\"", "\"", preg_replace("/\[([a-zA-Z0-9_\-\.\x7f-\xff]+)\]/s", "['\\1']", $var));
}
关于自己写的php模板引擎的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。
查看更多关于自己写的php模板引擎 自己写的php模板引擎怎么用的详细内容...