fork download
  1. <?php
  2.  
  3. $contents = '<a href="http://w...content-available-to-author-only...e.com/a">Works</a>
  4. <a href="http://w...content-available-to-author-only...e.com/a/b/c">Doesnt Work</a>
  5. <a href="http://w...content-available-to-author-only...e.com/x/y/z">Works</a>';
  6. $regexp = "/(<a\s[^>]*href=\")[^\"]*(\"[^>]*>.*<\/a>)/siU";
  7. $contents = preg_replace_callback($regexp, function($m) {
  8. return $m[1] . 'https://w...content-available-to-author-only...e.net/newlink/' . $m[2];
  9. }, $contents);
  10. echo $contents;
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
<a href="https://w...content-available-to-author-only...e.net/newlink/">Works</a>
<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>