求指點

來源:互聯網
上載者:User
我用了個笨方法將以下數組
$rules = array('student/|之間不管什麼1|.html' => 'm=A1&a=show&id=#1','|之間不管什麼1|/|之間不管什麼|2.html' => 'm=Category&type=#1&page=#2');//處理成這樣一個結果數組:$rules = array('m=A1&a=show&id=|之間不管什麼1|' => 'student/#1.html','m=Category&type=|之間不管什麼1|&page=|之間不管什麼2|' => '#1/#2.html');


不知道大家的方法會是怎樣的,想參照一下.以下我的笨方法
$aRule = array();   //結果//反轉規則與URLforeach($rules  as $key => $value){$reg = '#\|.*\|#U';$matchCount = 0; //匹配到的數量$aMatchResult = array(); //匹配到的內容$matchCount = preg_match_all($reg, $key, $aMatchResult);if(!$matchCount){continue;}$aMatchResult = $aMatchResult[0];   //取內容//根據內容數量產生相應條數的#n$aPartern = array();for ($i = 0; $i < count($aMatchResult); $i++){$aPartern[] = '#' . ($i + 1);}$tmpKey = str_replace($aPartern, $aMatchResult, $value);  //將value裡的一個個#1, #2.. #n換成對應的括弧$tmpValue = str_replace($aMatchResult, $aPartern, $key);  //將key裡的一個個 |豎號1|, |豎號2|.. |豎號n|換成對應的 #n$aRule[$tmpKey] = $tmpValue;}


回複討論(解決方案)

$rules = array(    'student/|之間不管什麼1|.html' => 'm=A1&a=show&id=#1',    '|之間不管什麼1|/|之間不管什麼|2.html' => 'm=Category&type=#1&page=#2');foreach($rules as $k=>$v) {  $t = preg_split('/(\|[^|]+\|)/', $k, -1, PREG_SPLIT_DELIM_CAPTURE);  preg_match_all('/#(\d+)/', $v, $r);  $k = preg_replace('/#(\d+)/e', '$t[$1]', $v);  for($i=0; $iArray  
(
[m=A1&a=show&id=|之間不管什麼1|] => student/#1.html
[m=Category&type=|之間不管什麼1|&page=/] => #1/#22.html
)

你的規則似乎有點問題

沒有的,呵呵,你不太瞭解詳細而已,沒事了,這是我們項目具體的事了.謝謝哦!

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.