2013-04-27 68 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