Search code examples
phphyperlinkhref

How to get all href values in an html page using PHP


I want to get the value of href links on a html page.


Solution

  • You can't do that with PHP. You need to use JavaScript to get the value of href links on an html page:

    var arr = [];
    for(var i=0, l = document.links; i<l.length; i++) {
      arr.push(l[i].href);
    }
    

    You can then do an AJAX Post to send the links to your server which PHP can then process.