fork download
  1. <?php
  2. $html = '<first_section>
  3. <second_section>
  4. <third_section id="2">
  5. <title>Mrs</title>
  6. </third_section>
  7. </second_section>
  8. </first_section>';
  9.  
  10. $xml = simplexml_load_string($html);
  11. $section = $xml->xpath("//third_section[@id='2']")[0];
  12. $section["id"] = 3;
  13. echo $xml->asXML();
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
<?xml version="1.0"?>
<first_section>
     <second_section>
          <third_section id="3">
               <title>Mrs</title>
          </third_section>
     </second_section>
 </first_section>