title: PHP when writing to file, How to prepend and append text to a file with existing text?
body: <p>I'm creating a xml file with PHP here is some sample code.</p>
  
  <pre><code> $myFile = "example_file.xml";
      $fh = fopen($myFile, 'w');
    while($row = mysql_fetch_array($result))
    {
  
    $stringData = "&lt;field name=\"id\"&gt;$page_id&lt;/field&gt;
                                &lt;field name=\"url\"&gt;http://myfundi.co.za/a/$page_url&lt;/field&gt;
                                &lt;field name=\"title\"&gt;$pagetitle&lt;/field&gt;
                                &lt;field name=\"content\"&gt;$bodytext&lt;/field&gt;
                                &lt;field name=\"site\"&gt;Myfundi&lt;/field&gt;";
                            fwrite($fh, $stringData);
      }             
  
      fclose($fh);
  </code></pre>
  
  <p>What I need to do is when the first content is written to the text file, I need to prepend and append some more text. </p>
  
  <p>I need to prepend  and append  to the data that already exists.</p>
  
  <p>How can I do that?</p>
  
  <p>Thanks</p>