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 Quote Link to comment 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. Quote Link to comment 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; } ?> Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Brandon_R Posted October 4, 2009 Author Share Posted October 4, 2009 It sure did thanks guys. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.