當前位置: 首頁>>代碼示例>>PHP>>正文


PHP CTemplate::Parse方法代碼示例

本文整理匯總了PHP中CTemplate::Parse方法的典型用法代碼示例。如果您正苦於以下問題:PHP CTemplate::Parse方法的具體用法?PHP CTemplate::Parse怎麽用?PHP CTemplate::Parse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在CTemplate的用法示例。


在下文中一共展示了CTemplate::Parse方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: Parse

 function Parse()
 {
     $content = $this->_template;
     // Mask {{ and }} for later substitution with { and }
     $content = str_replace("{{", "_<<<_", $content);
     $content = str_replace("}}", "_>>>_", $content);
     // Parse includes
     $search = "#{INCLUDE}(.*){/INCLUDE}#isU";
     preg_match_all($search, $content, $matches, PREG_SET_ORDER);
     foreach ($matches as $match) {
         $incfile = dirname($this->_tpl_file) . DIRECTORY_SEPARATOR . $match[1];
         $t = new CTemplate($incfile);
         $t->SetValues($this->_values);
         $search = sprintf("#{INCLUDE}%s\\{/INCLUDE}#isU", $match[1]);
         $replace = str_replace("\$", "\\\$", $t->Parse());
         $content = preg_replace($search, $replace, $content);
     }
     // Replace single fields
     foreach ($this->_values as $token => $value) {
         $content = str_replace('{' . $token . '}', $value, $content);
     }
     // Replace template blocks
     foreach ($this->_blockdata as $token => $value) {
         $content = str_replace('{BLOCK_' . $token . '}', $value, $content);
     }
     // Parse PHP
     if ($this->_parse_php) {
         $content = $this->_parsePHP($content);
     }
     // Strip empty template placeholders
     if (!$this->_debug) {
         $content = preg_replace("/{.*}/U", "", $content);
     }
     // Now convert the {{ and }} replacements back to { and }
     $content = str_replace("_<<<_", "{", $content);
     $content = str_replace("_>>>_", "}", $content);
     // Return content
     $this->_content = $content;
     return $this->_content;
 }
開發者ID:ratan203,項目名稱:phpsyntaxtree,代碼行數:40,代碼來源:class.template.php


注:本文中的CTemplate::Parse方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。