-2

Possible Duplicate:
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

4
  • What is the relation between the question and the title? Commented Mar 14, 2011 at 16:33
  • Do you mean <?php echo $game['info']['cleanname']; ?> Commented Mar 14, 2011 at 16:37
  • @mike B yes and it does relate to the question. damn you guys are quick to downvote. Commented Mar 14, 2011 at 21:30
  • @user658911 I didn't downvote nor vote to close. Commented Mar 15, 2011 at 21:24

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

would it replace all the occurences of the code above
and does it work for nested arrays

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.