yhi Posted October 16, 2017 Share Posted October 16, 2017 i want to add comments in JS & PHP files there are 22K files so i cant do it manually i need a php script which i can run & it should add my comment in all files please give me a script which will add my comment in top line of all PHP and Js file i can run script separately for php & JS PS please make sure script dont change anything else on those php& JS source code thanks for the help Link to comment Share on other sites More sharing options...
benanamen Posted October 16, 2017 Share Posted October 16, 2017 please give me a script We are not a code on demand service. Either post in the "for hire" section or show your attempt. Link to comment Share on other sites More sharing options...
ginerjm Posted October 16, 2017 Share Posted October 16, 2017 At the very least you could at least be polite about it. Link to comment Share on other sites More sharing options...
Sepodati Posted October 16, 2017 Share Posted October 16, 2017 I'll get you started. fopen() Link to comment Share on other sites More sharing options...
ginerjm Posted October 16, 2017 Share Posted October 16, 2017 Yes - a fopen would be a good start. But - as I re-read your post - if you have written (?) 22k files, then why can't you figure this out for yourself??? Or maybe you didn't write them. In that case what is this 'comment' you want to add? A statement of authorship perhaps? Link to comment Share on other sites More sharing options...
mac_gyver Posted October 16, 2017 Share Posted October 16, 2017 if you have 22K files making up a site, you are doing something wrong. you should instead invest your time in dynamically outputting the content using a single file with the content being stored in a database. Link to comment Share on other sites More sharing options...
yhi Posted October 17, 2017 Author Share Posted October 17, 2017 We are not a code on demand service. Either post in the "for hire" section or show your attempt. seems fair here <?php $comment=" blah blah"; foreach ($files as $file){ $code=file_get_contents("$file"); $finalcode="$comment$code"; $writefile = fopen("$file","w"); echo fwrite($writefile,"$finalcode"); fclose($file); } ?> i am not sure how to read read all files name in all directories Link to comment Share on other sites More sharing options...
yhi Posted October 17, 2017 Author Share Posted October 17, 2017 At the very least you could at least be polite about it. sorry i am not good in english do i didnt know i am being rude sorry Link to comment Share on other sites More sharing options...
Phi11W Posted October 17, 2017 Share Posted October 17, 2017 i want to add comments in JS & PHP files there are 22K files so i cant do it manually i need a php script which i can run & it should add my comment in all files And what purpose are these "comments" going to fulfil? Presumably, you'll be adding the same thing to each and every one, which begs the question - what's so important that it has to be in every file? Boiler plate comment blocks are probably of very little practical value or, indeed, downright "harmful" (see: https://dzone.com/articles/meaningless-docblocks). Regards, Phill W. Link to comment Share on other sites More sharing options...
ginerjm Posted October 17, 2017 Share Posted October 17, 2017 Notwithstanding the questions about "what is this comment?" you could do things a bit differently. 1 - add a \n\r to the comment so that it stands on a line by itself. 2 - use file_put_contents to output the new file. 3 - Read the Manual to learn more about PHP. Link to comment Share on other sites More sharing options...
benanamen Posted October 17, 2017 Share Posted October 17, 2017 if you have 22K files making up a site, you are doing something wrong. This was my very first thought when I read the post. OP, what is your current setup that you have 22k files for a site? That is the real problem that needs to be resolved. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.