PHP: how to write in between content of existing file?
<p>How to write in between content of existing file? </p>

<p>I tried to use fseek() to seek a new position and write the new content, but it replaces old content to the new string after seek position.</p>

<p>My aim is to put new contents after 5 characters of existing file.</p>

<p>Old content: <code>AAAAABBBBB</code>, desired content: <code>AAAAAnewcontentBBBBB</code></p>

<pre><code>$file_handler = fopen('putty.log','w');
$new_content = 'this is new content';

fseek($file_handler,5);

echo ftell($file_handler); //5
fwrite($file_handler,$new_content);
</code></pre>

<p>old content replaced with <code>NULLNULLNULLNULLNULLthis is new content</code></p>
