Multiple file_put_contents with with str_replace?
<p>I am trying to replace multiple parts of a string in a file with <code>file_put_contents</code>.
Essentially what the function does is finds a particular phrase in the file (which are in the <code>$new</code> and <code>$old</code> arrays and replaces it.</p>

<pre><code>$file_path = "hello.txt";
$file_string = file_get_contents($file_path);
function replace_string_in_file($replace_old, $replace_new) {
    global $file_string; global $file_path;
    if(is_array($replace_old)) {
        for($i = 0; $i &lt; count($replace_old); $i++) {
            $replace = str_replace($replace_old[$i], $replace_new[$i], $file_string);
            file_put_contents($file_path, $replace); // overwrite
        }
    }
}
$old = array("hello8", "hello9"); // what to look for
$new = array("hello0", "hello3"); // what to replace with
replace_string_in_file($old, $new);
</code></pre>

<p>hello.txt is: <code>hello8 hello1 hello2 hello9</code></p>

<p>Unfortunately it outputs: <code>hello8 hello1 hello2 hello3</code></p>

<p>So it outputs only 1 change when it should have outputted 2:
<code>hello0 hello1 hello2 hello3</code></p>
