PhpRegex替換

來源:互聯網
上載者:User
PHP替換
 1function 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.
24function view_macro_transclude($args)
25{
26  global $pagestore, $ParseEngine, $ParseObject, $HeadingOffset, $PgTbl;
27  static $visited_array = array();
28  static $visited_count = 0;
29  
30  $previousHeadingOffset = $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;

 

參照:

http://www.php.net/manual/zh/function.preg-replace.php

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.