discuz模板解析注釋

2021-09-05 23:56:11 字數 4223 閱讀 8302

1php2

3function

parse_template(

$tplfile

,$objfile

) 13

14$template

=fread

($fp

,filesize

($tplfile

));15

fclose

($fp

);16

17//

匹配變數

18//雙引號(單引號)內的\具有轉義所以,要得到乙個\必須寫為\\;要得到乙個$必須寫為\$;最後結果為\$,可在正則中使用的變數符號

19$var_regexp

=「((\\\$[a-za

-z_\x7f

-\xff][a-za

-z0-9_\x7f

-\xff]

*)(\[[a-za

-z0-9_\-\

.\」\』\[\]\$\x7f

-\xff]

+\])

*)」;

2021

//匹配字元

22$const_regexp

=「([a-za

-z_\x7f

-\xff][a-za

-z0-9_\x7f

-\xff]

*)」;

2324

//清除縮排(tab)

25$template

=preg_replace(」/

([\n\r]

+)\t

+/s」

,「\\1「

,$template

);26

27//

清除注釋(),方便後續操作,不需要匹配多餘的

28$template

=preg_replace(」/

\\-\-

\\-\-

\>/s」,

「」,$template

);29

30//

將替換成乙個硬回車(\n)

31$template

=str_replace

(」」,

「=\」\\n\「

?>」,

$template

);32

33//

匹配多種變數形式,包括$***[」***x」]與$***[$***]、或$***

34$template

=preg_replace(」/

\/s」,

「=\\1

?>」,

$template

);35

36//

使用/e修正符,可使替換元素以php**執行後,再進行replace.

37$template

=preg_replace(」/

$var_regexp

/es」

,「addquote(』

=\\1

?>

』)」,

$template

);38

39//

再次替換疊加字串變數

40$template

=preg_replace(」/\\=

\\=

$var_regexp\?

\>\?

\>/

es」,

「addquote(』

=\\1

?>

』)」,

$template

);41

42//

子模板巢狀解析

43$template

=preg_replace(」/

[\n\r\t]

*\[\n\r\t]

*/is」

,「\n

include

template(』\\

1′); 

?>

\n」,

$template

);44

$template

=preg_replace(」/

[\n\r\t]

*\[\n\r\t]

*/is」

,「\n

include

template(\\

1); 

?>

\n」,

$template

);45

46//

eval語法解析

47$template

=preg_replace(」/

[\n\r\t]

*\[\n\r\t]

*/ies」

,「stripvtags(』\n

\\1; ?>

\n』,

」)」,

$template

);48

49//

echo語法解析

50$template

=preg_replace(」/

[\n\r\t]

*\[\n\r\t]

*/ies」

,「stripvtags(』\n

echo\\1

; ?>

\n』,

」)」,

$template

);51

52//

elseif語法解析

53$template

=preg_replace(」/

[\n\r\t]

*\[\n\r\t]

*/ies」

,「stripvtags(』\n

} elseif

(\\1

) [\n\r\t]

*/is」

,「\n

} else

[\n\r]*(

.+?)[\n\r]

*\[\n\r\t]

*/ies」

,「stripvtags(』\n

<?if (

is_array

(\\1

))  } ?>\n』)」, $template);

60$template = preg_replace(」/[\n\r\t]*\[\n\r\t]*(.+?)[\n\r\t]*\[\n\r\t]*/ies」, 「stripvtags(』\n if(is_array(\\1))  } 

?>

\n』)」

,$template

);61

$template

=preg_replace(」/

[\n\r\t]

*\[\n\r]*(

.+?)[\n\r]

*\[\n\r\t]

*/ies」

,「stripvtags(』\n

if(\\

1)  ?>\n』)」, $template);62}

6364

//常量直接輸出..

65$template = preg_replace(」/\/s」, 「=\\1?>」, $template);

6667

//相臨定界符清除(使語法更加連貫)

68$template = preg_replace(」/ \?\>[\n\r]*\

6970

if(!@$fp = fopen($objfile, 『wb』)) 

7374

//轉換鏈結中的&符號為&使編譯模板讀取時能夠正常不會將其視為引用..

//轉換&避免&以引用方式執行..

83function transamp($str) 

8990

//將$var字串,轉換為可執行的php**形式,並返回其結果..

91//\」轉換為」,將為[***]轉換為[』***』]

92function addquote($var) 

9596

//設定語言變數

97function languagevar($var) 

100//清理或轉換標籤為php語法

101function stripvtags($expr, $statement) 

106107

?>

Discuz 模板解析語法

x2.5新增內容 從 discuz x2.5 開始,模板檔案支援 php 副檔名的格式,你可以建立例如 template mytext common forum discuz.php 檔案,php 的模板檔案中你只需在原有 htm 的模板檔案開頭新增一行 即可,如 php 的模板檔案的模板資料內容將...

IDEA 方法注釋模板和類注釋模板

1.類注釋模板 在編輯區域輸入你想要注釋的內容,點選應用,再點選儲存,在你建立新的類時就可以自動生成了 2.方法注釋模板 開啟 file setting editor livetemplates 點選右邊上面那個綠色的 號,選擇template group雙擊,然後彈出乙個視窗,起名,然後點選ok ...

eclipse注釋模板

檔案 files 注釋標籤 型別 types 注釋標籤 類的注釋 classname description author comsys date 字段 fields 注釋標籤 fields 用一句話描述這個變數表示什麼 建構函式標籤 建立乙個新的例項 title description 方法 co...