Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 2 down vote accepted

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

Assuming you use Linux or an UNIX environment

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

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

share|improve this answer
I want to add the notice in the source files. – Sourav Jul 19 '11 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 Jul 19 '11 at 9:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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