I think that this question already had a question, but I can not find it. Maybe the solution is too simple ... Anyway, I have a flat file and you want the user to change values based on the name. I already sorted the creation of a new name + value pair using mode fopen('a'), using jQuery to send an AJAX call with newValueand newName. But let's say that the content is as follows:
host|http:www.stackoverflow.com
folder|/questions/
folder2|/users/
And now I want to change the value folder. Therefore, I will post in folderhow oldNameand /tags/how newValue. What is the best way to rewrite meaning? The order in the list does not matter, and the name will always be on the left, and then |(pipe), value, and then new-line.
My first thought was to read the list, save it in an array, find everything [0]for oldName, and then change [1]which belongs to it, and then write it back to the file. But I feel there is a better way around this? Any ideas? Perhaps regex ?
source
share