开发者

Help with regular expression

开发者 https://www.devze.com 2023-01-17 22:18 出处:网络
I am converting some associative array database calls to object orientated results. So I wo开发者_JS百科uld love a reg exp I can use in find and replace to convert :

I am converting some associative array database calls to object orientated results. So I wo开发者_JS百科uld love a reg exp I can use in find and replace to convert :

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


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.

0

精彩评论

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

关注公众号