PHP replacement
1 function split_curly_options1 ($ text)
2 {
3 $ retarr = array ();
4
5 If (empty ($ text )){
6 return $ retarr;
7}
8 $ Options = preg_split ('|, |', $ text );
9
10 foreach ($ options as $ OPT ){
11 if (empty ($ OPT) {continue ;}
12 if (preg_match ('/(. *) = (. *)/', $ opt, $ match )){
13 $ retarr [$ match [1] = $ match [2];
14} else {
15 $ retarr [$ opt] = '';
16}
17}
18 return $ retarr;
19}
20
21 [[pagelist {size = 5, Category = XX, titlelength = Z9, countname = xxcount} <div> % title % | % title %-% time % </div>]
22
23 // This macro transcludes another page into a wiki page.
24 function view_macro_transclude ($ ARGs)
25 {
26 Global $ pagestore, $ parseengine, $ parseobject, $ headingoffset, $ pgtbl;
27 static $ visited_array = array ();
28 static $ visited_count = 0;
29
30 $ previusheadingoffset = $ headingoffset; // backup Previous Version
31
32 // check for curlyoptions, and split them
33
34 preg_match ("/^ (? : \ S * {([^] *)})? \ S * (. *) $/", $ ARGs, $ Arg );
35
36 $ Options = split_curly_options1 ($ Arg [1]);
37 $ search = $ Arg [2];
38
39 $ Q1 = $ pagestore-> DBH-> query ("select t1.title, t1.version, t1.author, t1.time ,".
40 "t1.username, length (t1.body), t1.comment ,".
41 "t1.mutable, max (t2.version )".
42 "from $ pgtbl as T1, $ pgtbl as t2 ".
43 "where t1.title = t2.title ".
44 "group by t2.title, t1.version ".
45 "having t1.version = max (t2.version )".
46 "Limit 0,". $ options [size]);
47
48 $ text = '';
49
50 $ patenarr = array ('(% title % )',
51 '(% time % )'
52 );
53
54 while ($ result = $ pagestore-> DBH-> result ($ Q1 )))
55 {
56
57 $ arr = array ($ result [0], $ result [3]);
58
59 // $ text = $ text. preg_replace ('(% ([A-Z] +) %)', "make_result ('$ 1')", $ search );
60 $ text = $ text. preg_replace ($ patenarr, $ arr, $ search );
61}
62 return $ text;
Refer:
Http://www.php.net/manual/zh/function.preg-replace.php