问题
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.
The style of tag I want to parse looks like {{ form | form_name }}
回答1:
REGEX is the way to go.
\{\{ *form *\| *(\S+) *\}\}
should do the trick nicely.
A bit of explaining:
\{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).
来源:https://stackoverflow.com/questions/7650833/how-to-parse-django-style-template-tags