在 PHP 中解析 django 样式模板标签的最佳方法是什么?我知道有很多 PHP 模板库,但实际上我只需要在从数据库中检索数据时解析一个标签.
What's the best way to parse django style template tags in PHP? I know there are plenty of templating libraries for PHP, but I literally just need to parse one tag when I retrieve data from my database.
我要解析的标签样式看起来像 {{ form |form_name }}
The style of tag I want to parse looks like {{ form | form_name }}
REGEX 是要走的路.
REGEX is the way to go.
{{ *form *| *(S+) *}}
应该可以很好地解决问题.
should do the trick nicely.
稍微解释一下:
{
和 }
将分别匹配 {
和 }
.*
将匹配 0 到无限空格字符 (
).(S+)
将匹配 1 到无限个非空格字符(a, B, 3, _ etc
).{
and }
will each match {
and }
respectively.*
will match for 0 to infinite space characters (
).(S+)
will match for 1 to infinite non-space characters (a, B, 3, _ etc
).这篇关于如何解析 django 样式模板标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!