title: PHP - Function to Load XML / Modify / Save
body: <p>I would like to open the file, made the modification, save it as it was before, but my function does not work, and I'm not sure why.</p>
  
  <p>Here is my function:</p>
  
  <pre><code>function modifyXml($candidateFile){
  
  $xml = simplexml_load_file($candidateFile);
  
  $searches = ["\n&lt;/DESIGNATION_PLU&gt;"];
  $replacements = ['&lt;/DESIGNATION_PLU&gt;'];
  
  $xml = str_replace(  $searches, $replacements, $xml-&gt;asXml() ) ;
  file_put_contents($candidateFile, $xml);
  }
  </code></pre>
  
  <p>This is where I'm using it, as part of another function:</p>
  
  <pre><code>foreach ($candidateFiles as $candidateFile) {
  
              modifyXml($candidateFile);
  
              $this-&gt;processXml($candidateFile, $destdir);
  
              if ($this-&gt;input-&gt;getOption('cleanup')) {
                  $this-&gt;addInfo("Deleting source XML file: " . basename($candidateFile));
                  @unlink($candidateFile);
              }
  
              $completedPercentage = ( ++$i == $fileCount) ? 100 : floor($i * $singleFilePercentage);
              $this-&gt;addInfo("$completedPercentage% complete.");
          }
  </code></pre>
  
  <p>Does anyone know what am I doing wrong?</p>