• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

PHP to pull Meta tag description code help

ITahmed

New Member
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
 
Eh?

So the user types in a URL and automatically, the Meta description that is on that page is retrieved?

PHP:
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:

PHP:
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;
 
Last edited:
Back
Top