in questo tutorial imparerete come ottenere tutti i link presenti in una pagina web grazie alla funzione file_get_contents che mette a disposizione PHP!
/**
* @author Jay Gilford
*/
// regular expression pattern to match all links on a page
$pattern = ‘%]+href="(?P[^"]+)"[^>*]*>(?P[^< ]+)%si’;
// Webpage URL to get links from
$url = ‘http://www.sastgroup.com/’;
// Fetch contents of whole page
$page_content = file_get_contents($url);
// Get all matches of links and put them into the $matches variable
preg_match_all($pattern, $page_content, $matches);
// Variable to hold all of our urls and their text
$urls = array();
// Loop through each array item
foreach($matches[‘url’] as $k=>$v) {
// combine the url and text into it’s own key for ease of access
$urls[$k] = array(‘url’ => $v,‘text’ => $matches[‘text’][$k]);
}
// For display purposes only to show the contents of $urls
echo print_r($urls, true);
fonte: www.sastgroup.com





