need a find/replace command to fix my require_once
| From: | Daevid Vincent | Date: | Fri, 20 Nov 2009 01:43:44 +0000 |
| Subject: | need a find/replace command to fix my require_once | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-299948@lists.php.net to get a copy of this message | ||
I was reading this: http://pear.php.net/manual/en/standards.including.php
and it states:
"Note: include_once and require_once are statements, not functions.
Parentheses should not surround the subject filename."
I never knew that. I've always (wrongly) used:
require_once('/path/to/my/file');
Anyone have a bash command line snippet (or other code is fine too I guess)
that will fix all my directory tree?
The tricks are that I think there can be several variations and several
instances with a given file too:
require_once('/path/to/my/file');
require_once ('/path/to/my/file');
require_once("/path/to/my/file");
require_once(ROOTPATH."/my/file");
etc. Note the space before the parens, the single vs. double quotes and the
use of a global define.
I think this regex should work:
require_once\s?\((.*?)\);
I just don't know the magic sed/awk/grep/whatever to do the search and
replace on all my .php files recursively.
This seems like a useful 'routine' to post up on that page, as I'm sure I'm
not the only one who didn't know this little subtlety (considering PHP
doesn't puke on it either).