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
Post a Comment