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
精彩评论