国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > CMS > PhpCMS > 正文

phpcms 的模板模板機(jī)制

2024-09-10 07:15:27
字體:
供稿:網(wǎng)友

phpcms有自己的一套模板機(jī)制,代碼如下:

  1. function template_parse($str$istag = 0) 
  2.  
  3.   { 
  4.  
  5.   $str = preg_replace("/([/n/r]+)/t+/s","//1",$str); 
  6.  
  7.   $str = preg_replace("//</!/-/-/{(.+?)/}/-/-/>/s""{//1}",$str); 
  8.  
  9.   $str = preg_replace("//{template/s+(.+)/}/","<?php include template(//1); ?>",$str); 相當(dāng)于 
  10.  
  11.   $str = preg_replace("//{include/s+(.+)/}/","<?php include //1; ?>",$str); 
  12.  
  13.   $str = preg_replace("//{php/s+(.+)/}/","<?php //1?>",$str); 
  14.  
  15.   $str = preg_replace("//{if/s+(.+?)/}/","<?php if(//1) { ?>",$str); 
  16.  
  17.   $str = preg_replace("//{else/}/","<?php } else { ?>",$str); 
  18.  
  19.   $str = preg_replace("//{elseif/s+(.+?)/}/","<?php } elseif (//1) { ?>",$str); 
  20.  
  21.   $str = preg_replace("//{//if/}/","<?php } ?>",$str); 
  22.  
  23.   $str = preg_replace("//{loop/s+(/S+)/s+(/S+)/}/","<?php if(is_array(//1)) foreach(//1 AS //2) { ?>",$str); 
  24.  
  25.   $str = preg_replace("//{loop/s+(/S+)/s+(/S+)/s+(/S+)/}/""<?php if(is_array(//1)) foreach(//1 AS //2 => //3) { ?>",$str); 
  26.  
  27.   $str = preg_replace("//{//loop/}/","<?php } ?>",$str); 
  28.  
  29.   $str = preg_replace("//{//get/}/","<?php } unset(/$DATA); ?>",$str); 
  30.  
  31.   $str = preg_replace("//{tag_([^}]+)/}/e""get_tag('//1')"$str); 
  32.  
  33.   $str = preg_replace("//{get/s+([^}]+)/}/e""get_parse('//1')"$str); 
  34.  
  35.   $str = preg_replace("//{([a-zA-Z_/x7f-/xff][a-zA-Z0-9_/x7 f-/xff:]*/(([^{}]*)/))/}/","<?php echo //1;?>",$str); 
  36.  
  37.   $str = preg_replace("//{//$([a-zA-Z_/x7f-/xff][a-zA-Z0-9_ /x7f-/xff:]*/(([^{}]*)/))/}/","<?php echo //1;?>",$str); 
  38.  
  39.   $str = preg_replace("//{(//$[a-zA-Z_/x7f-/xff][a-zA-Z0-9_/x7f-/xff]*)/}/","< ?php echo //1;?>",$str); 
  40.  
  41.   $str = preg_replace("//{(//$[a-zA-Z0-9_/[/]/'/"/$/x7f-/xff]+)/}/es""addquote('<?php echo //1;?>')",$str); 
  42.  
  43.   $str = preg_replace("//{([A-Z_/x7f-/xff][A-Z0-9_/x7f-/xff ]*)/}/s""<?php echo //1;?>",$str); 
  44.  
  45.   if(!$istag$str = "<?php defined('IN_PHPCMS') or exit('Access Denied'); ?>".$str;  //Vevb.com 
  46.  
  47.   return $str
  48.  
  49.   } 

其中先容幾個(gè)關(guān)鍵點(diǎn):

/s 是將 代表任意符號(hào)的"."變成任意的符號(hào)。dedecms /s 是空格的意思.

$str = preg_replace("/([/n/r]+)/t+/s","//1",$str); 取括號(hào)中一個(gè)或者多個(gè)回車換行的字符并且外面有至少一個(gè)制表符的字符.

$str = preg_replace("//</!/-/-/{(.+?)/}/-/-/>/s", "{//1}",$str); //這是將注釋父里面變成大括號(hào).

$str = preg_replace("//{include/s+(.+)/}/","<?php include //1; ?>",$str); //輸進(jìn)的 include 將被替換成 <?php include ?>

$str = preg_replace("//{php/s+(.+)/}/","<?php //1?>",$str); //例如 {php echo "a"} 將被替換成 <?php echo "a";?>

$str = preg_replace("//{if/s+(.+?)/}/","<?php if(//1) { ?>",$str);

$str = preg_replace("//{else/}/","<?php } else { ?>",$str); 這個(gè)事講{if } {else} 替換<?php if ($a='1') echo a; else {a='b'}?> 替換的是 if +空格 +一個(gè)或者多個(gè)字符 if (//1)是取括號(hào)里的值也就是內(nèi)存地址的值

$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+)/}/", "<?php if(is_array(//1)) foreach(//1 AS //2 => //3) { ?>",$str); // 這連個(gè)似乎拿出來有點(diǎn)疏漏http://www.pcbaike.net/,大家可以研究研究,測試時(shí)沒有合適的主要是取第一個(gè)括號(hào)中或者第二個(gè)括號(hào)中的數(shù)據(jù)假如是數(shù)組替換成foreach循環(huán) $str = preg_replace("//{get/s+([^}]+)/}/e", "get_parse('//1')", $str);

這個(gè)事替換get標(biāo)簽實(shí)質(zhì)上是調(diào)用一個(gè) get_parse 函數(shù),有參函數(shù).

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 孝义市| 阿拉善左旗| 湖南省| 唐河县| 竹北市| 河津市| 田阳县| 赫章县| 麻栗坡县| 崇州市| 双鸭山市| 常宁市| 丹东市| 永嘉县| 沙洋县| 万宁市| 务川| 沧州市| 合水县| 湘阴县| 金山区| 龙江县| 汉阴县| 金门县| 阿图什市| 荔波县| 浦北县| 天水市| 图木舒克市| 德清县| 黑河市| 门头沟区| 花垣县| 长子县| 浦江县| 汉寿县| 仁化县| 普安县| 东宁县| 江陵县| 三台县|