I need to refactor some code across multiple php files stored in multiple folders.
I need to replace code instances like:
trim(ucfirst($userinfo['first_name'])).' '.trim(ucfirst($userinfo['last_name']))
With text (in place, within those files) as:
formatUserName($userinfo['first_name'],$userinfo['last_name'])
Note that the $ variable name will be different, but everything else will be the same*.
I am on a Windows machine, but have php and perl installed – would prefer to use that instead of sed.
I have Notepad++, but not sure if that can handle such search and replacement operations.
*There are variations of this line in our code, which once I have an understanding of how to build the proper regex, I’ll attempt on my own.
With Notepad++ version 6.0, you can do:
find what :
trim\(ucfirst\((\$\w+\['first_name'\])\)\)\.' '\.trim\(ucfirst\((\$\w+\['last_name'\])\)\)replace with:
formatUserName\(\1,\2\)