How to change one same line of php code that resides in 100 different folders?
I want to change a line inside one php file (ex: ABCDEFG to 123456). How to do so if I want to change the same line but reside in, say, 100 different folders without goes to each and single file/folder? Thanks. TA.
You could open the file with fopen and try to stream the file to a string variable and then do a str_replace function call. Then you would just use fwrite to overwrite the contents of the file with the modified string.
To hit all the files and folders just use cwdir to get the current highest level directory then run a dir command and create a loop that recursively visits every folder looking for the php files you want to modify and run the string replace operation on each. Put that into a function to simplify this for yourself.
Ok so that is the easy way to do it for now. but it is still a huge pain in the ass. What you should really be focusing on is the design and code repetition issues with your code. You shouldn’t have the same thing repeated in multiple places. Instead put the code/html snippet into one file then call an include or require from the files you want to use them in. Place the include where you want this to take effect. Then if you have to change anything in the future you just go to that one file and edit it. The change then goes into effect in all the files.
Look up coupling and cohesion in programming. Create concepts, you will learn a lot there. Also learn recursion, this is a must for any programmer worth his salt.
If its the same line in each file, It might just be quicker to go and copy and paste that line into each file rather than waiting for an answer on here and then getting it to work. The question was asked 10 hours ago, You could probably change them all in about half an hour if you just copy and paste