fork(1) download
  1. <?php
  2.  
  3. $html = <<<DATA
  4. <a href="http://w...content-available-to-author-only...e.com">text</a>
  5. <a href="http://m...content-available-to-author-only...e.com">text1</a>
  6. <a href='http://m...content-available-to-author-only...e.com'>text2</a>
  7. <a href='http://w...content-available-to-author-only...e.com'>text3</a>
  8. <a href='http://w...content-available-to-author-only...e.com'>text4</a>
  9. <a href="http://w...content-available-to-author-only...n.com/id.php?site=mysite.com">text5</a>
  10. DATA;
  11.  
  12. $dom = new DOMDocument('1.0', 'UTF-8');
  13. $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
  14.  
  15. $xpath = new DOMXPath($dom);
  16. $links = $xpath->query('//*[@href and not(starts-with(@href, "http://m...content-available-to-author-only...e.com")) and not(starts-with(@href, "http://w...content-available-to-author-only...e.com"))]');
  17.  
  18. $res_arr = array();
  19. foreach($links as $link) {
  20. array_push($res_arr, $link->getAttribute('href'));
  21. }
  22. print_r($res_arr);
  23.  
  24.  
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
Array
(
    [0] => http://w...content-available-to-author-only...e.com
    [1] => http://w...content-available-to-author-only...n.com/id.php?site=mysite.com
)