Hamlets666 Posted January 22, 2007 Share Posted January 22, 2007 Hey guys ;) Could you help me with this one:imagine there is a folder secret with many subfolders and subsubfolders and....I need to edit all files ( str_replace("was so", "is now", $fileweread); ) Quote Link to comment https://forums.phpfreaks.com/topic/35245-auto-edit-all-files-in-subfolders/ Share on other sites More sharing options...
Hamlets666 Posted January 23, 2007 Author Share Posted January 23, 2007 Omg, where are you all super programmers? Quote Link to comment https://forums.phpfreaks.com/topic/35245-auto-edit-all-files-in-subfolders/#findComment-167075 Share on other sites More sharing options...
ted_chou12 Posted January 23, 2007 Share Posted January 23, 2007 i dont quite understand what you mean by subfolders... Do you have a specific file extension? like .txt files? or you want to edit every file with any extension?Ted Quote Link to comment https://forums.phpfreaks.com/topic/35245-auto-edit-all-files-in-subfolders/#findComment-167088 Share on other sites More sharing options...
trq Posted January 23, 2007 Share Posted January 23, 2007 Is this on a Linux server? Bash and sed would be much more suited to the task, and you could even run it from within PHP. Quote Link to comment https://forums.phpfreaks.com/topic/35245-auto-edit-all-files-in-subfolders/#findComment-167090 Share on other sites More sharing options...
ted_chou12 Posted January 23, 2007 Share Posted January 23, 2007 [code]<?phpforeach (glob("*.txt") as $filename) {// get contents of file, line by line, and put into an array$data = file_get_contents($filename);$data = str_replace("was so", "is now", $data);$file = fopen($filename, "w");fwrite($file, $data);// close filefclose($file);}?> [/code]I believe this would work for the txt files in a directory but not its subdirectory...hope it helps.Ted Quote Link to comment https://forums.phpfreaks.com/topic/35245-auto-edit-all-files-in-subfolders/#findComment-167093 Share on other sites More sharing options...
trochia Posted January 23, 2007 Share Posted January 23, 2007 Sounds more like he wants to hack with this routine...as if was on a local box, an editor would do the functions :-( Quote Link to comment https://forums.phpfreaks.com/topic/35245-auto-edit-all-files-in-subfolders/#findComment-167176 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.