[英]Get title and meta tags from Facebook page with PHP
如何從Facebook頁面獲取標題和所有meta標簽?
我有以下代碼:
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']
您真的不需要處理元標記,只需調用Graph API:
$data = file_get_contents('https://graph.facebook.com/bladauhu'); //example page
對於每個公共頁面,即使沒有應用程序也可以使用。
我認為網址不正確,請將您的網址更改為https://graph.facebook.com/showmeapp
使用簡單的HTML DOM解析器
http://simplehtmldom.sourceforge.net/
試試下面的代碼:
<?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.