php - Extract Title and Description from multiple URLs -
i have list of links articles. trying use php extract title , description of them @ once. want article title hyperlink url , description displayed below in italics.
my issue this: works when 1 link, when try multiple links or if duplicate code , manually paste in each link, doesn't work. below code have works 1 link. ideas?
<html> <a href="http://bit.ly/18efx87"> <b><?php function gettitle($url){ $str = file_get_contents($url); if(strlen($str)>0){ preg_match("/\<title\>(.*)\<\/title\>/",$str,$title); return $title[1]; } } echo gettitle("http://bit.ly/18efx87"); ?></b><br> </a> <i><?php $tags = get_meta_tags('http://bit.ly/18efx87'); echo $tags['description']; ?></i> </html>
i assume mean multiple urls, work. :
<html> <?php function gettitle($url){ @$str = file_get_contents($url); // suppressing warning if(strlen($str)>0){ preg_match("/\<title\>(.*)\<\/title\>/",$str,$title); return $title[1]; } else { return false; } } $urls = array('http://bit.ly/18efx87', 'url2'); foreach($urls $url) { $title = gettitle($url); if($title === false) { continue; } echo '<a href="' . $url . '"><b>'; echo $title; echo '</b></a><br><i>'; $tags = get_meta_tags($url); echo $tags['description'] . '</i>'; } ?> </html>
Comments
Post a Comment