How to get all the links to pages on a particular site?

I want to program php to get all the links on a page on my site, since I want to check pagerank for every page of my site, is there a tool or library or implemented algorithm in php to get the whole page of a link to a specific site?

+4
source share
1 answer

You can try the following:

<?php $original_file = file_get_contents("http://www.your_domain.com/page"); $stripped_file = strip_tags($original_file, "<a>"); preg_match_all("/<a(?:[^>]*)href=\"([^\"]*)\"(?:[^>]*)>(?:[^<]*)<\/a>/is", $stripped_file, $matches); ?> 

$ matches [0] will contain full A tags; ex: <a href="link">text</a>

$ matches [1] will contain only HREF in A tags; ex: link

Hope this helps you. Hello!

+6
source

Source: https://habr.com/ru/post/1385832/


All Articles