Re: need a find/replace command to fix my require_once

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2009-11-19 at 17:43 -0800, Daevid Vincent wrote:

> 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).
> 
> 

You could try something like this:

find .  -maxdepth 1 -name "*.php" -type f -exec sed -i 's/find
text/replace text/' {} \;

Note that the find and replace strings are regular expressions,
separated by the / character here, so ()'s will need to be escaped as
they have a special meaning in regular expressions. The maxdepth
parameter of find can be set to higher than 1 to let the script work
recursively on files within directories.

Thanks,
Ash
http://www.ashleysheridan.co.uk



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux