fork(1) download
  1. <?php
  2.  
  3. $html = <<<DATA
  4. <html>
  5.   <title>Random Website</title>
  6.  
  7.   <body>
  8.  
  9.   Click <a href="http://d...content-available-to-author-only...z.com">here</a> for foobar
  10.  
  11.   Another site is http://w...content-available-to-author-only...n.com
  12.   <a href="http://w...content-available-to-author-only...n.com/test">Test 1</a>
  13.   <a href="http://w...content-available-to-author-only...n.com/test">Test 2</a>
  14.   <Strong>NOT A LINK</strong>
  15.   </body>
  16.  
  17.   </html>
  18. DATA;
  19.  
  20. $dom = new DOMDocument;
  21. $dom->loadHTML($html);
  22. $xpath = new DOMXPath($dom);
  23. $arr = array();
  24. $links = $xpath->query('//a[contains(@href, "www.domain.com")]');
  25.  
  26. foreach($links as $link) {
  27. array_push($arr, $link->getAttribute("href"));
  28. }
  29.  
  30. print_r($arr);
  31.  
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
Array
(
    [0] => http://w...content-available-to-author-only...n.com/test
)