[英]Get title and meta tags from Facebook page with PHP
How can I get the title and all the meta tags from a Facebook page? 如何从Facebook页面获取标题和所有meta标签?
I have this code: 我有以下代码:
function getMetaData($url){
// get meta tags
$meta=get_meta_tags($url);
// store page
$page=file_get_contents($url);
// find where the title CONTENT begins
$titleStart=strpos($page,'<title>')+7;
// find how long the title is
$titleLength=strpos($page,'</title>')-$titleStart;
// extract title from $page
$meta['title']=substr($page,$titleStart,$titleLength);
// return array of data
return $meta;
}
$tags=getMetaData('https://www.facebook.com/showmeapp?filter=3');
echo 'Title: '.$tags['title'];
echo '<br />';
echo 'Description: '.$tags['description'];
echo '<br />';
echo 'Keywords: '.$tags['keywords']
Example: https://www.facebook.com/showmeapp?filter=3 例如: https : //www.facebook.com/showmeapp?filter = 3
You really don´t need to deal with the Metatags, just call the Graph API: 您真的不需要处理元标记,只需调用Graph API:
$data = file_get_contents('https://graph.facebook.com/bladauhu'); //example page
Works even without an App, for every public page. 对于每个公共页面,即使没有应用程序也可以使用。
我认为网址不正确,请将您的网址更改为https://graph.facebook.com/showmeapp
Use Simple HTML DOM Parser 使用简单的HTML DOM解析器
http://simplehtmldom.sourceforge.net/ http://simplehtmldom.sourceforge.net/
Try below code: 试试下面的代码:
<?php
require_once('simple_html_dom.php');
$page=$html = file_get_html('https://www.facebook.com/showmeapp');
$title= $html->find('meta[name="title"]',0)->content;
echo 'Title: '.$title ;
echo '<br />';
$description= $html->find('meta[name="description"]',0)->content;
echo 'Description: '.$description;
echo '<br />';
$keywords= $html->find('meta[name="keywords"]',0)->content;
echo 'Keywords: '.$keywords;
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.