开发者

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

开发者 https://www.devze.com 2023-02-16 22:31 出处:网络
This question already has answers here: Closed 11 years ago. Possible Dupl开发者_Python百科icate: PHP templating using custom code replacing using regex
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

精彩评论

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