fork download
  1. <?php
  2.  
  3. $contents = '<div class="xxx">
  4. <a href="/start">start</a>
  5.  
  6. <a href="/start/world">World</a>
  7.  
  8. <a href="/start/world/fantastic-yyy-zz">Fantastic-yyy-zz</a>
  9. peter-hey
  10. </div>';
  11.  
  12. $doc = new DOMDocument();
  13. $doc->loadXML($contents);
  14.  
  15. $tagName = 'a';
  16.  
  17. $tags = $doc->getElementsByTagName($tagName);
  18.  
  19. foreach ($tags as $tag) {
  20. $newValue = str_replace('-', ' ', $tag->nodeValue);
  21. $tag->nodeValue = $newValue;
  22. }
  23.  
  24. echo $doc->saveHTML();
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
<div class="xxx">
<a href="/start">start</a>

<a href="/start/world">World</a>

<a href="/start/world/fantastic-yyy-zz">Fantastic yyy zz</a>
  peter-hey
</div>