title: find and replace values in a flat-file using PHP
body: <p>I'd think there was a question on this already, but I can't find one. Maybe the solution is too easy... Anyway, I have a flat-file and want to let the user change the values based on a name. I've already sorted out creating new name+value-pairs using the <code>fopen('a')</code> mode, using jQuery to send the AJAX call with <code>newValue</code> and <code>newName</code>. But say the content looks like this:</p>
  
  <pre><code>host|http:www.stackoverflow.com
  folder|/questions/
  folder2|/users/
  </code></pre>
  
  <p>And now I want to change the <code>folder</code> value. So I'll send in <code>folder</code> as <code>oldName</code> and <code>/tags/</code> as <code>newValue</code>. What's the best way to overwrite the value? The order in the list doesn't matter, and the name will always be on the left, followed by a <code>|</code>(pipe), the value and then a <code>new-line</code>.</p>
  
  <p>My first thought was to read the list, store it in an array, search all the <code>[0]</code>'s for <code>oldName</code>, then change the <code>[1]</code> that belongs to it, and then write it back to a file. But I feel there is a better way around this? Any ideas? Maybe <a href="http://www.thinkgeek.com/tshirts-apparel/xkcd/dad3/" rel="nofollow noreferrer">regex</a>?</p>