您可以匹配嵌套的功能,例如:
$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