开发者

Use a Regex to convert Smarty syntax to PHP syntax [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Dupl开发者_Python百科icate:

PHP templating using custom code replacing using regex

Hi,

I would like to convert

<a href="{$game.url}">{$game.info.cleanname}</a>

to

<a href="$game['url']">$game['info']['cleanname']</a>

using preg_replace


There was a question asking for exactly the same yesterday:
PHP templating using custom code replacing using regex

Simply add a second preg_replace version (or more) to match the other cases:

preg_replace('/\{\$(\w+)\.(\w+)\}/', '\\$$1[\'$2\']', $src);

If you need more help with that: https://stackoverflow.com/questions/89718/is-there-anything-like-regexbuddy-in-the-open-source-world

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜