title: How to edit headers/footers from a document using PHPWord?
body: <p>I am using PHPWord to create documents. What I need to do is edit the header/footer content of an existing docx/odt document. It was not very hard to add the content to a document. But I've spent the whole day on the internet to find a solution. Here is the code through which I am only being able to add content to existing header/footer content:</p>
  
  <pre><code>$source = "DumpFiles/".$_FILES['file']['name'];
      $fileName = $_FILES['file']['name'];
      $phpWord = \PhpOffice\PhpWord\IOFactory::load($source);
      echo "File Loaded";
  
      // Get Sections from the imported document...
      $sections = $phpWord-&gt;getSections();
      $section = $sections[0];
  
      // Adding Header and Footer Content
      if(isset($_POST['headerContent']) &amp;&amp; $_POST['headerContent']!=null)
      {
          $headert = $section-&gt;createHeader();
          $table = $headert-&gt;addTable();
          $table-&gt;addRow();
          $table-&gt;addCell(4500)-&gt;addText($_POST['headerContent']);
      }
      if(isset($_POST['footerContent']) &amp;&amp; $_POST['footerContent'])
      {
          $footervar = $section-&gt;createFooter();
          $table = $footervar-&gt;addTable();
          $table-&gt;addRow();
          $table-&gt;addCell(4500)-&gt;addText($_POST['footerContent']);
      }
  </code></pre>
  
  <p>I understand that the usage of <code>global</code> variables directly is a bad practice. :-p</p>
  
  <p>I would rectify these discrepancies in my code once I get the existing code working.</p>
  
  <p>A solution with an example would be greatly appreciated.</p>