ホームページ php教程 php手册 Kangsheng 製品から抽出されたテンプレート クラス (discuz)

Kangsheng 製品から抽出されたテンプレート クラス (discuz)

Jun 21, 2016 am 08:54 AM
gt replace template this

コードをコピー コードは次のとおりです:


/*template.class.php
@ Kangsheng Weibo テンプレート抽出クラス このテンプレートは時間をかけて独自に作成すると使いやすいと思います。 by Lei Rijin
@ が ctt テンプレートを調べました。これは phpcms テンプレートに似ていますか? ? ^_^ ふふふ! ! !
@ Weibo http://weibo.com/lrjxgl
@ 良いものはみんなで共有します。抽出について質問がある場合は、
@ に問い合わせてください。デフォルトのテンプレート ファイルは .htm
$tpl = new template ('skin',"default");
$tpl->gt;objdir='tpp';
$tpl->rewrite=true;//書き換えを有効にするにはサーバーのサポートが必要です
$tpl-> ;rewrite_rule=array(array("/index.php/"),array("index.html")); //ルールを書き換えます
$tpl->assign("indexurl"," index.php") ;
$tpl->assign("str","私は文字列ラララです");
$tpl->assign("ec","エコーアウトされました");
$tpl->assign("subhtml","{subtpl ttt} これはテンプレート ファイルを導入するために使用され、これは ttt.htm を導入するために使用されます");
$tpl->assign ("a ",array('dasdasd'.'bbbbbbb','cccccccccccc'));
$tpl->assign("i",1); ");
*/
if(!define("CHARSET"))define("CHARSET","gb2312");//文字エンコーディング
if(!define("DIR_TPL")) 定義("DIR_TPL ","tpl");//デフォルトのテンプレート ディレクトリ
if(!define("DIR_DATA"))define("DIR_DATA","data");//デフォルトのデータ ディレクトリ
if(! generated(" DEBUG"))define("DEBUG",0);//デフォルトの実行モード
class template {
//note var
public $rewrite=false;//擬似を有効にするかどうかstatic rewrite
public $rewrite_rule=array(); //疑似静的ルールを設定します
public $defaulttpldir;//デフォルトのテンプレート
public $tpldir;//テンプレート ディレクトリ
public $objdir;/ /コンパイル キャッシュ ディレクトリ
public $tplfile;//テンプレート ファイル
public $objfile;//コンパイル ファイル
public $tplid=1;//テンプレート番号
public $currdir='default'; //現在のスタイルディレクトリ
public $vars=array();//メモ変数テーブル
public $removeblanks=false;//スペースを削除
public $stdout='display';//出力タイプ
関数 __construct ($tplid, $currdir) {
$this->template($tplid, $currdir);
}
関数テンプレート($tplid, $currdir) {
ob_start ();
if(file_exists(DIR_TPL.'/'.$currdir)) {
$this->currdir = $currdir
$this->tplid = $tplid; } else {
$this->currdir = 'default';
$this->tplid = 1;
}
$this->defaulttpldir = DIR_TPL.'/default';
$ this->tpldir = DIR_TPL.'/'.$this->currdir;
$this->objdir = DIR_DATA.'/cache/tpl';
if(version_compare(PHP_VERSION) , '5' ) == -1) {
register_shutdown_function(array(&$this, '__destruct'))
}
}
//note public
function assign($ k, $v ) {
$this->vars[$k] = $v;
}
//note public
function display($file) {
extract($) this->vars, EXTR_SKIP);
include $this->getObj($file)
}
function getObj($file, $tpldir = '') {
$subdir = ($pos = strpos($file, '/')) === false ? '' : substr($file, 0, $pos);
$file = $subdir ? 1) : $ ファイル;
$this->tplfile = ($tpldir ? $tpldir : $this->tpldir).'/'.($subdir ? $subdir.'/' : '')。 $file.' .htm';
$this->objfile = $this->objdir.'/'.($tpldir ? '' : $this->tplid.'_')サブディレクトリ ? $subdir .'_' : '').$file.'.php';
//デフォルトのディレクトリに注意してください
if(@filemtime($this->tplfile) === FALSE) {
$ this->tplfile = $this->defaulttpldir.'/'.($subdir ? $subdir.'/' : '').$file.'.htm'; >//note 比較の有効期限が切れているかどうかを判断します
if(!file_exists($this->objfile) DEBUG && @filemtime($this->objfile) < filemtime($this->tplfile)) {
$this->compile();
}
return $this->objfile;
}
function getTpl($file) {
$subdir = ($pos = strpos($file, '/')) === false ? '' : substr($file, 0, $pos);
$file = $subdir ($file, $pos + 1) : $file;
$tplfile = $this->tpldir.'/'.($subdir ? $subdir.'/' : '').$file.'.htm';
if(@filemtime ($tplfile) == = FALSE) {
$tplfile = $this->defaulttpldir.'/'.($subdir ? $subdir.'/' : '').$file.'.htm';
}
return $tplfile;
}
functioncompile() {
$var_regexp = "@?\$[a-zA-Z_]w*(?:[[w. "'[]$] +])*";
$vtag_regexp = "";
$const_regexp = "{([w]+)}";
$template = file_get_contents($this->tplfile);
for($i = 1; $i < ;= 3; $i++) {
if(strpos($template, '{subtpl') !== FALSE) {
if(DEBUG == 2) {
$ template = str_replace('{ subtpl ', '{tpl ', $template);
} else {
$template = preg_replace("/[nrt]*{subtpls+([a-z0-9_:/]) +)}[nrt] */ies", "file_get_contents($this->getTpl('\1'))", $template);
}
}
}
$remove = array(
'/(^rn)/*.+?(rn)*/(rn)/is',
'///note.+?(rn)/i',
'///デバッグ。+?(rn)/i'、
'/(^rn)(st)+/'、
'/(rn)/'、
);$this->removeblanks && $template = preg_replace($remove, '', $template);
$template = preg_replace("//s", "{\1}", $template);
$template = preg_replace("/{($var_regexp)}/", "", $template);
$template = preg_replace("/{($const_regexp)}/", "", $template);
$template = preg_replace("/(?", $template);
$template = preg_replace("/=(@?\$[a-zA-Z_]w*)(([[\$[]w]+])+)?>/ies" , "$this->arrayindex('\1', '\2')", $template);
$template = preg_replace("/{{eval (.*?)}}/ies", "$this->stripvtag('')", $template);
$template = preg_replace("/{eval (.*?)}/ies", "$this->stripvtag('')", $template);
$template = preg_replace("/[nrt]*{echos+(.+?)}[nrt]*/ies", "$this->stripvtag('' 、'')"、$template);
$template = preg_replace("/{for (.*?)}/ies", "$this->stripvtag('')", $template) ;
$template = preg_replace("/{elseifs+(.+?)}/ies", "$this->stripvtag('')", $template );
for($i=0; $i$template = preg_replace("/{loops+$vtag_regexps+$vtag_regexps+$vtag_regexp}(.+?){/loop}/ies" , "$this->loopsection('\1', '\2', '\3', '\4')", $template);
$template = preg_replace("/{loops+$vtag_regexps+$vtag_regexp}(.+?){/loop}/ies", "$this->loopsection('\1', '', '\2' 、'\3')"、$template);
}
$template = preg_replace("/{ifs+(.+?)}/ies", "$this->stripvtag('')" 、$template);
$template = preg_replace("/{tpls+(w+?)}/is", "getObj("\1");?>", $template);
$template = preg_replace("/{tpls+(.+?)}/ise", "$this->stripvtag('getObj("\1"); ?> ;')", $template);
$template = preg_replace("/{tmptpls+(w+?)}/is", "getObj("\1", $this->objdir);?>" 、$template);
$template = preg_replace("/{tmptpls+(.+?)}/ise", "$this->stripvtag('getObj("\1", $this- >objdir); ?>')", $template);
$template = preg_replace("/{else}/is", "", $template);
$template = preg_replace("/{/if}/is", "", $template);
$template = preg_replace("/{/for}/is", "", $template);
$template = preg_replace("/$const_regexp/", "", $template);//note {else} 也符合常量格式,此处注意要先後顺序
$template = preg_replace("/(\$[a-zA-Z_]w+[)([a-zA-Z_]w+)]/i", "\1'\2']", $template);
$fp = fopen($this->objfile, 'w');
fwrite($fp, $template);
fclose($fp);
}
function arrayindex($name, $items) {
$items = preg_replace("/[([a-zA-Z_]w*)]/is", "['\1' ]", $items);
return "";
}
functionstripvtag($s) {
$vtag_regexp = "";
return preg_replace("/$vtag_regexp/is", "\1", str_replace("\"", '"', $s));
}
関数ループセクション($arr, $k, $v, $statement) {
$arr = $this->stripvtag($arr);
$k = $this->stripvtag( $k);
$v = $this->stripvtag($v);
$statement("\"", '"', $statement);
return $k " foreach((array)$arr as $k => $v) {?>$statement" : "$statement";
}
function __destruct() {
$content = ob_get_contents();
//处理 rewrite
if($this->rewrite) {
$arr=$this->rewrite_rule;
$s=$arr[0];
$content=preg_replace($s,$e,$)
}
ob_end_clean();
echo $content;
}
$tpl = 新しいテンプレート('スキン',"デフォルト"); $tpl->objdir='tpp';
$tpl->rewrite=true;//开启rewrite 必要服务器のサポート
$tpl->rewrite_rule=array("/index.php/ "),array("index.html")); //書き換え
$tpl->assign("indexurl","index.php");
$tpl->assign("str ","我是字符串啦啦啦");
$tpl->assign("ec","我是被echo出来的");
$tpl->assign("subhtml" ,"{subtpl ttt}これはモジュール ファイルを挿入するために使用されます、これは ttt.htm に挿入されます"); cccccccccccc'));
$tpl->assign("i",1);


新規建 tpl/default/index.html



复制代


代码如下:






無題ドキュメント



1. 文字列の割り当て: < ;br />
{$str}


{loop $v}{$ v}, {/loop}
または

{loop $a $key $val }{$val},{/loop}

3.{$subhtml}

{subtpl ttt}
4. 私は {$indexurl } になっていたことが判明しました。
5. echo

{echo $ec}
実際には、6*7*8
{ を加算、減算、乗算、除算することもできます。 echo 6 *7*8;}
7. これらは一般的に使用されるものですが、他に分からないことは何ですか

;


tpl/default/ttt.html を作成
tpp ディレクトリを作成 OK




このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

Huawei GT3 ProとGT4の違いは何ですか? Huawei GT3 ProとGT4の違いは何ですか? Dec 29, 2023 pm 02:27 PM

多くのユーザーはスマートウォッチを選ぶときにファーウェイブランドを選択しますが、その中でもファーウェイ GT3pro と GT4 は非常に人気のある選択肢であり、多くのユーザーはファーウェイ GT3pro と GT4 の違いに興味を持っています。 Huawei GT3pro と GT4 の違いは何ですか? 1. 外観 GT4: 46mm と 41mm、材質はガラスミラー + ステンレススチールボディ + 高解像度ファイバーバックシェルです。 GT3pro: 46.6mm および 42.9mm、材質はサファイアガラス + チタンボディ/セラミックボディ + セラミックバックシェルです。 2. 健全な GT4: 最新の Huawei Truseen5.5+ アルゴリズムを使用すると、結果はより正確になります。 GT3pro: ECG 心電図と血管と安全性を追加

修正: Windows 11 で Snipping ツールが機能しない 修正: Windows 11 で Snipping ツールが機能しない Aug 24, 2023 am 09:48 AM

Windows 11 で Snipping Tool が機能しない理由 問題の根本原因を理解すると、適切な解決策を見つけるのに役立ちます。 Snipping Tool が正しく動作しない主な理由は次のとおりです。 フォーカス アシスタントがオンになっている: これにより、Snipping Tool が開かなくなります。破損したアプリケーション: 起動時にスニッピング ツールがクラッシュする場合は、破損している可能性があります。古いグラフィック ドライバー: 互換性のないドライバーは、スニッピング ツールに干渉する可能性があります。他のアプリケーションからの干渉: 実行中の他のアプリケーションが Snipping Tool と競合する可能性があります。証明書の有効期限が切れています: アップグレード プロセス中のエラーにより、この問題が発生する可能性があります。これらの簡単な解決策は、ほとんどのユーザーに適しており、特別な技術知識は必要ありません。 1. Windows および Microsoft Store アプリを更新する

iPhoneでApp Storeに接続できないエラーを修正する方法 iPhoneでApp Storeに接続できないエラーを修正する方法 Jul 29, 2023 am 08:22 AM

パート 1: 最初のトラブルシューティング手順 Apple のシステムステータスを確認する: 複雑な解決策を掘り下げる前に、基本から始めましょう。問題はデバイスにあるのではなく、Apple のサーバーがダウンしている可能性があります。 Apple のシステム ステータス ページにアクセスして、AppStore が適切に動作しているかどうかを確認してください。問題があれば、Apple が修正してくれるのを待つしかありません。インターネット接続を確認します。「AppStore に接続できません」問題は接続不良が原因である場合があるため、安定したインターネット接続があることを確認してください。 Wi-Fi とモバイル データを切り替えるか、ネットワーク設定をリセットしてみてください ([一般] > [リセット] > [ネットワーク設定のリセット] > [設定])。 iOS バージョンを更新します。

REPLACE 関数を使用して MySQL の文字列の指定された部分を置換する方法 REPLACE 関数を使用して MySQL の文字列の指定された部分を置換する方法 Jul 25, 2023 pm 01:18 PM

MySQL は、データを処理および操作するためのさまざまな機能を提供する、一般的に使用されるリレーショナル データベース管理システムです。このうち、REPLACE関数は文字列の指定した部分を置き換える関数です。この記事では、MySQL で文字列を置換するための REPLACE 関数の使用方法を紹介し、コード例を通してその使用法を示します。まず、REPLACE 関数の構文を見てみましょう: REPLACE(str,search_str,replace_str)。

Python での文字列検索と置換のテクニックは何ですか? Python での文字列検索と置換のテクニックは何ですか? Oct 20, 2023 am 11:42 AM

Python での文字列検索と置換のテクニックは何ですか? (具体的なコード例) Python では文字列が一般的なデータ型であり、日常のプログラミングでは文字列の検索や置換操作によく遭遇します。この記事では、一般的な文字列の検索と置換のテクニックを、具体的なコード例とともに紹介します。文字列内の特定の部分文字列を検索するには、文字列の find() メソッドまたは Index() メソッドを使用できます。 find() メソッドは、文字列内で最初に出現した部分文字列のインデックスを返します。

Golang と Template パッケージ: パーソナライズされたユーザー インターフェイスの作成 Golang と Template パッケージ: パーソナライズされたユーザー インターフェイスの作成 Jul 18, 2023 am 10:27 AM

Golang とテンプレート パッケージ: パーソナライズされたユーザー インターフェイスを作成する 最新のソフトウェア開発では、ユーザー インターフェイスは多くの場合、ユーザーがソフトウェアと対話するための最も直接的な方法です。使いやすく美しいユーザー インターフェイスを提供するために、開発者はユーザー インターフェイスを作成およびカスタマイズするための柔軟なツールを必要とします。 Golang では、開発者は Template パッケージを使用してこの目標を達成できます。この記事では、Golang および Template パッケージの基本的な使用法を紹介し、コード例を通じてパーソナライズされたユーザー インターフェイスを作成する方法を示します。

Golang のテンプレート パッケージによるデータ視覚化 Golang のテンプレート パッケージによるデータ視覚化 Jul 17, 2023 am 09:01 AM

Golang のテンプレート パッケージによるデータの視覚化 ビッグ データ時代の到来により、データの視覚化は情報処理と分析の重要な手段の 1 つになりました。データの視覚化により、データを簡潔かつ直感的な方法で表示できるため、人々がデータをよりよく理解して分析できるようになります。 Golang では、Template パッケージを使用してデータ視覚化機能を実装できます。この記事では、Golang の Template パッケージを使用してデータ視覚化を実現する方法を紹介し、コード例を示します。ゴランテム

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

See all articles