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 Quote Link to comment https://forums.phpfreaks.com/topic/305374-auto-html-comments/ Share on other sites More sharing options...
benanamen Posted October 16, 2017 Share Posted October 16, 2017 (edited) please give me a script We are not a code on demand service. Either post in the "for hire" section or show your attempt. Edited October 16, 2017 by benanamen 2 Quote Link to comment https://forums.phpfreaks.com/topic/305374-auto-html-comments/#findComment-1552746 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. 1 Quote Link to comment https://forums.phpfreaks.com/topic/305374-auto-html-comments/#findComment-1552750 Share on other sites More sharing options...
Sepodati Posted October 16, 2017 Share Posted October 16, 2017 I'll get you started. fopen() Quote Link to comment https://forums.phpfreaks.com/topic/305374-auto-html-comments/#findComment-1552751 Share on other sites More sharing options...
ginerjm Posted October 16, 2017 Share Posted October 16, 2017 (edited) 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? Edited October 16, 2017 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/305374-auto-html-comments/#findComment-1552752 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. Quote Link to comment https://forums.phpfreaks.com/topic/305374-auto-html-comments/#findComment-1552753 Share on other sites More sharing options...
yhi Posted October 17, 2017 Author Share Posted October 17, 2017 (edited) 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 Edited October 17, 2017 by yhi Quote Link to comment https://forums.phpfreaks.com/topic/305374-auto-html-comments/#findComment-1552757 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 Quote Link to comment https://forums.phpfreaks.com/topic/305374-auto-html-comments/#findComment-1552758 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. Quote Link to comment https://forums.phpfreaks.com/topic/305374-auto-html-comments/#findComment-1552761 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. Quote Link to comment https://forums.phpfreaks.com/topic/305374-auto-html-comments/#findComment-1552768 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. Quote Link to comment https://forums.phpfreaks.com/topic/305374-auto-html-comments/#findComment-1552776 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.