Link to home
Start Free TrialLog in
Avatar of linuxrox
linuxroxFlag for United States of America

asked on

add comment to php files

Hello!  I have a project i'm working on that i have failed to include comments at the top of all of my php files *rolleyes*
anyway, I need to create a script that reads all php files in a certain directory and recurses directories; and simply write a comment lets say in the form of /* my comment */ at the first line.  obviously i would rather not have the entire comment on one line.  rather i would like to have the comment taking up lets say, the first 100 characters per line then go to the next..like:  
/*  my comment that starts here
* the rest of my comment
*/
i know this may sound trivial and it was my mistake in forgetting to do this but i'm lazy and there are too many files to edit  :)
anyone have a solution for this?
thank you very much in advance!
                               
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

>at the top of all of my php files
the comments with /* etc  */ need to be inside the <?php  tag ...  ?>
the /* can indeed span several lines
to comment only 1 line (ie the rest of it), use the following: // comment

to comment outside the <?php ?> tags, you have to use the html comment tags:
<!--  comment  -->
this also works like the /* */ over multiple lines
Avatar of linuxrox

ASKER

angelIII:  :)  you don't seem to understand....  I'm very aware of the comment structure of php :)
what i'm asking for is a way to open files using fopen to open all php files and insert a comment of my choosing at line 1 of all php files in recursive directories :)
also i fully understand html comments :)
-------thank you for the input but i'm not sure you fully understood what i'm asking for here.
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thx angelIII:
i'm getting ready to head to sleep but let me look at this first thing in the morning!  thanks for the response!
have a great night.
thanks again!
I agree with angelIII on the backup part, but for the replacement I would go with:

$comment = "\n/* Comment line 1\n * Comment line 2\n * Comment Line 3\n */";

$input = file_get_contents($copy_file);
$fout  = fopen($original_file, 'w');
fwrite($fout, str_replace('<'.'?php', '<'.'?php'.$comment, $input));
fclose($fout);

-r-
Roonaan, would that not put the comment before ANY <?php opening tag?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thx guys.  I had forgotten about this question! :)