如何解析 django 样式模板标签 [英] How to parse django style template tags

查看:30
本文介绍了如何解析 django 样式模板标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 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 样式模板标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆