php - Linux SED search replace multiple per line -


i have doosey here. new linux shell bare me...

i need replace whole bunch of php super globals in clients website php function made clean superglobals xss attacks.

here original code might like:

echo $_request['hello1'] . ' , ' . $_request['hello2']; 

i need this:

echo myclass::myfunction($_request['hello1']) . ' , ' . myclass::myfunction($_request['hello2']); 

the main issue, need search/replace on over 100 files! yikes!

so solution (in linux shell):

sudo sed -i 's/\$_request[.*\]/myclass::myfunction(&)/g' *.php 

this works great as-long-as 1 instance of "$_request" occurs per line... multiple instances, screws , this:

echo myclass::myfunction($_request['hello1'] . ' , ' . $_request['hello2']); 

i pulling hair out!

any linux shell experts out there can hope?

try sed command:

sed -i.bak 's/\$_request\[\([^]]*\)\]/myclass::myfunction(\1)/g' *.php 

or in perl:

perl -pe 's/\$_request\[([^]]*)\]/myclass::myfunction(\1)/g' file.php 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -