fork download
  1. <?php
  2. $html = '<html>
  3. <td style="vertical-align: top; border: 1px solid gray;">[COMMENT2]</td>
  4. </html>';
  5. $xml = simplexml_load_string($html);
  6.  
  7. // run an xpath query on the dom
  8. foreach ($xml->xpath("//td[text()='[COMMENT2]']") as &$td)
  9. $td[0] = 'Some other text';
  10. // just to make sure the html has indeed been changed
  11. echo $xml->asXML();
  12. ?>
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
<?xml version="1.0"?>
<html>
            <td style="vertical-align: top; border: 1px solid gray;">Some other text</td>
        </html>