View Full Version : PHP to pull Meta tag description code help
ITahmed
July 7th, 2006, 17:31
I am trying to create a php app, the user needs to be able to type the url to get the meta tag description from the url (clean)
One of my friend developer was able to get it in VB script which does not help me. I could not get anywhere in doing it in PHP. can you help.
Thanks
Ahmed
GamePhreak
July 7th, 2006, 20:11
Eh?
So the user types in a URL and automatically, the Meta description that is on that page is retrieved?
if(preg_match('@<meta[^>\r\n]*?name=("?)description\\1[^>\r\n]*?content=("?)(.*?)\\2[^>\r\n]*?/?>@', $file = file_get_contents($_POST['url']), $matches)) echo $matches[3];
else echo 'No description!';
That's very rough code and hasn't been tested, so try it out and tell me how it works or if it even does what you need.
Or, if you need each of the items in the description in an array:
if(preg_match('@<meta[^>\r\n]*?name=("?)description\\1[^>\r\n]*?content=("?)(.*?)\\2[^>\r\n]*?/?>@', $file = file_get_contents($_POST['url']), $matches)) $description = explode($matches[3], ',');
else $description = false;
Tree
July 7th, 2006, 20:15
You could do an fopen and then get all the source from meta tags
ITahmed
July 8th, 2006, 01:48
I will try that.... Thank you... will let you know.... :)
ITahmed
July 9th, 2006, 23:33
I had to tweak minor things, but it worked like a charm. YOU ROCK. Thank you it was driving me crazy.
Powered by vBulletin® Version 4.1.7 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.