tags:

views:

40

answers:

1

I am converting some associative array database calls to object orientated results. So I would love a reg exp I can use in find and replace to convert :

$rsName['fieldName'] to $rsName->fieldName

+2  A: 
preg_replace('/\$rsName\[\'(.*?)\'\]/', '$rsName->$1', $str);

Also, this won't take into account escaped ' in the key string.

How do you intend to run this? eval()? Bad idea, if so.

This also assumes that $rsName is a constant.

See it on CodePad.org.

alex
Thanks Alex will give it a go. Intend on running in in textmate to convert the code.
Daniel