1

What is the easiest way to insert copyright notice in lots of PHP files.
It's not possible to do it manually.

2 Answers 2

3

It's better to have a separate LICENSE file instead.

However, if you really want to do this, you can use a script:

for i in `command_giving_your_PHP_files`; do
  cp $i $i.bak
  cat LICENSE > $i
  cat $i.bak >> $i
done

Assuming you use Linux or an UNIX environment

3
  • yup i got Ubuntu 11, but not so familiar with it, can you explain a little bit about your answer
    – Sourav
    Commented Jul 19, 2011 at 9:57
  • 3
    Probably a good idea to clean up those .bak files; also, beware spaces in filenames. find -exec might provide a more robust solution.
    – tdammers
    Commented Jul 19, 2011 at 9:57
  • Remember to move <?php above the license text too.
    – Mchl
    Commented Jul 19, 2011 at 10:17
2

You should have some kind of templating mechanism in place (at the very least, a header.php and footer.php that you include in every page).

If you do, then it should be trivial to include a 'copyright message' in a part of the page that gets included everywhere already (typically, the footer); how exactly you do this depends on the template system.

If you don't have a template mechanism, I suggest you start adding one right away.

In case you still need to automate the file editing part, consider using sed; it's an excellent tool for the job (although the learning curve is a bit steep if you aren't used to regular expressions).

2
  • I want to add the notice in the source files.
    – Sourav
    Commented Jul 19, 2011 at 9:54
  • Oh, you mean like a comment? In that case, you can whip up a little PHP snippet and just cat it together with your source files, like Mihai Maruseac suggested.
    – tdammers
    Commented Jul 19, 2011 at 9:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.