Capture headers from this array

Right, I'm trying to grab links from a web page. links are stored in the $ links array.

Is there a way to capture the name (from the function below) from each link in the array. will it be a multidimensional array? How can i do this?

$links = Array(); $URL = 'http://www.theqlick.com'; // change it for urls to grab // grabs the urls from URL $file = file_get_html($URL); foreach ($file->find('a') as $theelement) { $links[] = url_to_absolute($URL, $theelement->href); } print_r($links); function getTitle($links) { //change it for the original titles. $str = file_get_contents("http://www.theqlick.com"); if ( strlen( $str )>0 ) { preg_match( "/\<title\>(.*)\<\/title\>/", $str, $title ); return $title[1]; } } $metatitle = getTitle(); echo $metatitle; 
+4
source share
1 answer

I don't have the right libraries installed to test this, but this should give you an idea of ​​where to start:

 $links = Array(); $URL = 'http://www.theqlick.com'; // change it for urls to grab // grabs the urls from URL $file = file_get_html($URL); foreach ($file->find('a') as $theelement) { $link = array(); $link['url'] = url_to_absolute($URL, $theelement->href); $link['title'] = getTitle($link['url']); $links[] = $link; } print_r($links); function getTitle($url) { $file = file_get_html($url); $titles = $file->find('title'); if (is_array($titles)) { return $titles[0]; } else { return null; } } 
+1
source

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


All Articles