I would like a command line function that I can run on any file to change the include("myinc.inc");
PHP statement to include 'myfile.inc';
I have made a start by adding the following to my ~/.bashrc file:
function makestandard() {
perl -p -i -e 's/include\("([\w\.]+)"\)/include '$1'/g' $*
}
I source ~/.bashrc;
and run the command at the command line as follows:
$ makestandard myfile.php
I get myfile.php modified but instead of capturing the included file name, the included file name is corrupted to be the name of the current file. As a uninformed guess, I think the bash $1
variable is interfering with the $1
perl regexp variable.
How can I fix this?
Background info (no need to read): We have started using PHP_CodeSniffer (phpcs) to sniff PHP code and report any bad "smells". Unfortunatly, phpcs doesn't fix the non-standard code, it only reports it. Hence I would like to make a script that fixes some of the easy and common non-standard elements of our PHP code. I plan to fill my makestandard
bash function with a bunch of perl pie.
Shell environment: Whatever is out-of-the-box in Ubuntu 10.04.