What is the easiest way to insert copyright notice in lots of PHP files.
It's not possible to do it manually.
2 Answers
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
-
yup i got Ubuntu 11, but not so familiar with it, can you explain a little bit about your answer– SouravCommented Jul 19, 2011 at 9:57
-
3Probably a good idea to clean up those .bak files; also, beware spaces in filenames.
find -exec
might provide a more robust solution.– tdammersCommented Jul 19, 2011 at 9:57 -
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).
-
-
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.– tdammersCommented Jul 19, 2011 at 9:56