I want to try figure out how to get the title and all meta tags from a webpage
<title>A common title</title> <meta name="keywords" content="Keywords blabla" /> <meta name="description" content="This is the description" />
This question seem to be asked and answered several times on stackoverflow but no answer cares about the language/charset of the webpage. For example, the script of shamittomar here Getting title and meta tags from external website only works for webpage in utf-8. This script fails to work, for ex it will return weird result for these sites:
http://www.开发者_运维问答tudou.com/
http://svmpbt.com/
(note: above websites are not mine but just examples)
Is there any way to do it in the right way, is there any available class to do this? Because Facebook Linter works correctly with above sites, I think there is available solution in PHP script.
Thanks.
You should use "get_meta_tags" function of php, it provides title, desscription and keyword. for it, refer this link : http://php.net/manual/en/function.get-meta-tags.php
And if you need more information, then you can use "file_get_contents" method also, that will return you source of that url, then parse it and extract the relevant information. Refer this link : http://in2.php.net/manual/en/function.file-get-contents.php
精彩评论