Results 1 to 2 of 2
I have a PHP script which, when run, brings a txt file into a text area in a browser, allows the browser user to edit the contents and then when ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 08-07-2013 #1
- Join Date
- Aug 2013
Editing txt files with PHP
It relies upon the PHP reading the WHOLE file, displaying the WHOLE file and writing back the WHOLE file. That can be cumbersome with big files, and makes writing guidance to GUI users complex and fallable.
I'd like to be able to read the file in to memory with PHP, have php and something like grep identify a "trigger" word or string, display the next "n" characters after the trigger in the GUI, let the user edit just the bit of the file shown, then write the browser-made changes back to the file in memory, and finally write the whole file back over the original file.
I have not the faintest idea how to do this....can anyone point me in the right direction; code snippets would be useful as well
Thanks for any help
- 08-08-2013 #2
Well, you can already load and save the file across the session of edits. All you need to do is to find the snippets in the file you want and present them for edit?
You can find bits in the already-loaded file contents with features like the php strpos function which will find substrings within a larger string. You can then use the php substr function to grab the bits out of the string you're passing to the client to edit. If you store the position of the edited string in the session somewhere, then the text can be replaced when it comes back in from the client.Linux user #126863 - see http://linuxcounter.net/