Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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
add comment

2 Answers

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
done

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
2  
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
add comment

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
add comment

Your Answer

 
discard

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.