Brandon_R Posted October 4, 2009 Share Posted October 4, 2009 Hello PHP Gurus and members alike i need some help with a piece of code. I would like to use php to get a website title and meta description from an inputted url. Thank You Brandon_R Link to comment https://forums.phpfreaks.com/topic/176477-using-php-to-get-a-site-title-and-meta-description-from-a-url/ Share on other sites More sharing options...
ProXy_ Posted October 4, 2009 Share Posted October 4, 2009 you can use file_get_contents("http://yoursite.com"); here is the title function function getMetaTitle($content){ $pattern = "|<[\s]*title[\s]*>([^<]+)<[\s]*/[\s]*title[\s]*>|Ui"; if(preg_match($pattern, $content, $match)) return $match[1]; else return false; } and its easy to get meta tags use this: $blah=get_meta_tags("http://yoursite.com"); hope this helps. Link to comment https://forums.phpfreaks.com/topic/176477-using-php-to-get-a-site-title-and-meta-description-from-a-url/#findComment-930253 Share on other sites More sharing options...
lipun4u Posted October 4, 2009 Share Posted October 4, 2009 <?php function getMetaDescription($content) { $metaDescription = false; $metaDescriptionPatterns = array("/]*>/Ui", "/]*>/Ui"); foreach ($metaDescriptionPatterns as $pattern) { if (preg_match($pattern, $content, $match)) $metaDescription = $match[1]; break; } return $metaDescription; } ?> Link to comment https://forums.phpfreaks.com/topic/176477-using-php-to-get-a-site-title-and-meta-description-from-a-url/#findComment-930259 Share on other sites More sharing options...
Brandon_R Posted October 4, 2009 Author Share Posted October 4, 2009 OK How to i get the site description only and not all meta tags Link to comment https://forums.phpfreaks.com/topic/176477-using-php-to-get-a-site-title-and-meta-description-from-a-url/#findComment-930261 Share on other sites More sharing options...
ProXy_ Posted October 4, 2009 Share Posted October 4, 2009 <?php $tags = get_meta_tags('http://www.example.com/'); echo $tags['author']; // name echo $tags['keywords']; // php documentation echo $tags['description']; // a php manual echo $tags['geo_position']; // 49.33;-86.59 ?> this was collected from php.net hope this helps. Link to comment https://forums.phpfreaks.com/topic/176477-using-php-to-get-a-site-title-and-meta-description-from-a-url/#findComment-930268 Share on other sites More sharing options...
Brandon_R Posted October 4, 2009 Author Share Posted October 4, 2009 It sure did thanks guys. Link to comment https://forums.phpfreaks.com/topic/176477-using-php-to-get-a-site-title-and-meta-description-from-a-url/#findComment-930285 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.