2013-04-27 69 views

回答

8

檢查下面的代碼:

$str = '{this}{is}a{my} {example}{{subject}}'; 

if(preg_match_all('/{+(.*?)}/', $str, $matches)) { 
    var_dump($matches[1]); 
} 

輸出:

array(5) { 
    [0] => 
    string(4) "this" 
    [1] => 
    string(2) "is" 
    [2] => 
    string(2) "my" 
    [3] => 
    string(7) "example" 
    [4] => 
    string(7) "subject" 
} 
+0

完美謝謝先生。對於任何感興趣的人來說,這個基本的上下文就是能夠從管理等中調用一個特定變量到你的模板而不會直接干擾核心代碼。我將添加額外的鏈接到其他與通過php preg_match創建您自己的模板解決方案有關的問題。感謝hek2mgl的答案。乾杯 - gitscripts.com – ajameswolf 2013-04-27 02:13:11

+0

這不工作:{tutu {toto} titi {tata}} – 2013-04-27 02:50:51

+0

@CasimiretHippolyte注意''不會工作,但這不是問題。正則表達式是針對特定用途的。你已經發布了一個不同的用法,所以不要指望我的正則表達式適用於不同的用法。 – hek2mgl 2013-04-27 02:55:42