fork(1) download
  1. <?php
  2.  
  3. $html = <<<DATA
  4. <a href="http://w...content-available-to-author-only...e.com/a">Works</a>
  5. <a href="http://w...content-available-to-author-only...e.com/a/b/c">Doesnt Work</a>
  6. <a href="http://w...content-available-to-author-only...e.com/x/y/z">Works</a>
  7. DATA;
  8.  
  9. $dom = new DOMDocument('1.0', 'UTF-8');
  10. $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
  11.  
  12. $xpath = new DOMXPath($dom);
  13. $links = $xpath->query('//a');
  14.  
  15. foreach($links as $link) {
  16. $link->setAttribute('href', 'https://w...content-available-to-author-only...e.net/newlink/');
  17. }
  18. echo $dom->saveHTML();
Success #stdin #stdout 0.03s 52480KB
stdin
Standard input is empty
stdout
<a href="https://w...content-available-to-author-only...e.net/newlink/">Works<a href="https://w...content-available-to-author-only...e.net/newlink/">Doesnt Work</a><a href="https://w...content-available-to-author-only...e.net/newlink/">Works</a></a>