您可以匹配嵌套的功能,例如:
$pattern = '~(@(?<func>\w++)\((?<param>[^)]*+)\)(?<content>(?>[^@]++|(?-4))*)@end)~';
或不命名捕获:
$pattern = '~(@(\w++)\(([^)]*+)\)((?>[^@]++|(?-4))*)@end)~';
请注意,你可以拥有的所有嵌套函数的所有内容,如果你把整个模式在先行(?=...)
图案的详细资料:
~ # pattern delimiter
( # open the first capturing group
@(\w++) # function name in the second capturing group
\( # literal (
([^)]*+) # param in the third capturing group
\) # literal)
( # open the fourth capturing group
(?> # open an atomic group
[^@]++ # all characters but @ one or more times
| # OR
(?-4) # the first capturing group (the fourth on the left, from the current position)
)* # close the atomic group, repeat zero or more times
) # close the fourth capturing group
@end
)~ # close the first capturing group, end delimiter
这不是答案,但是您的模板引擎看起来并不比使用PHP作为引擎本身更方便。 – invisal
PHP不支持视图继承:P –
@Petter:[Smarty的模板继承。](http://www.smarty.net/inheritance) – icktoofay