使用PHP从Facebook页面获取标题和元标记
如何从Facebook页面获取标题和所有元标记 我有以下代码:使用PHP从Facebook页面获取标题和元标记,php,facebook,title,Php,Facebook,Title,如何从Facebook页面获取标题和所有元标记 我有以下代码: 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;
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']
函数getMetaData($url){
//获取元标记
$meta=获取元数据标签($url);
//存储页面
$page=文件获取内容($url);
//查找标题内容的起始位置
$titleStart=strpos($page',)+7;
//查找标题的长度
$titleLength=strpos($page',)-$titleStart;
//从$page中提取标题
$meta['title']=substr($page,$titleStart,$titleLength);
//返回数据数组
返回$meta;
}
$tags=getMetaData('https://www.facebook.com/showmeapp?filter=3');
echo“Title:”.$tags['Title'];
回声“”; echo“Description:”.$tags['Description']; 回声“
”; echo'Keywords:'.$tags['Keywords']
示例:您确实不需要处理元标记,只需调用Graph API即可:
$data = file_get_contents('https://graph.facebook.com/bladauhu'); //example page
即使没有应用程序也可以工作,适用于每个公共页面。我认为url不正确。请将url更改为使用简单的HTML DOM解析器 请尝试以下代码:
<?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;
?>
你能告诉我出了什么问题吗?另外,你能解释一下示例链接吗?它似乎只是一个指向某个组织Facebook页面的链接……FB为任何形式的法律互动提供了一个API。——andyg0808我可以从一个随机的Facebook页面中提取描述或标题