Include a line in all scripts (#!/usr/bin/php)

hey,

I have a big problem… i have devolped a site on a server… and now that it is complete I have to install the site on other server… but the problem is that on new server I have to include this line:

#!/usr/bin/php

…Exist any way to do this auto?
I have more than 500 scripts :eye:

ThKS

try <?PHP instead of <?, some servers don’t allow the short tags.

You could do it with Perl.

This is untested but you get the idea:


#!/usr/bin/perl
opendir DIR, "." or die "Can't open current directory : $!";
while ($fn = readdir(DIR)) { // Get a filename
  if ($fn =~ /\.php$/i) { // Only PHP files
    open F, "< $fn" or die "Can't open $fn : $!"; // Open file for read
    @file = <F>; // Read entire file into an array
    close F; // Close file
    open F, "> $fn" or die "Can't open $fn for writing : $!"; // Open file for output
    print F "#!/usr/bin/php"; // Write PHP line
    print F @file; // Write rest of file
    close F; // Close the file
  }
}
closedir DIR;

That’ll add your line to the start of every php file in the current directory.

// doesn’t work as comment lines in Perl, so you need to remove the comments if you decide to use this script.

Also try it on a copy of your scripts first… :slight_smile:

thk u… I will try :slight_smile: