facebook分享链接脚本 [英] facebook share links script
本文介绍了facebook分享链接脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的页面
<html>
<head>
<title>mytitle</title>
</head>
<body>
my data
some pics...
</body>
data and some pics
</html>
我需要一个像脚本一样的facebook共享,所以当任何一个类型的网站url,这个脚本得到网站标题,图片作为缩略图和一些来自身体标签的数据..任何想法?
i need a facebook share like script ,, so when any one type a website url , this script get website title ,, images as thumbnails and some data from body tag .. any idea?
推荐答案
function getMetaTitle($content){
$pattern = "|<[\s]*title[\s]*>([^<]+)<[\s]*/[\s]*title[\s]*>|Ui";
if(preg_match($pattern, $content, $match))
return $match[1];
else
return false;
}
function getMetaDescription($content) {
$metaDescription = false;
$metaDescriptionPatterns = array("/]*>/Ui", "/]*>/Ui");
foreach ($metaDescriptionPatterns as $pattern) {
if (preg_match($pattern, $content, $match))
$metaDescription = $match[1];
break;
}
return $metaDescription;
}
function getExcerpt($content) {
$text = html_entity_decode($content);
$excerpt = array();
//match all tags
preg_match_all("|<[^>]+>(.*)]+>|", $text, $p, PREG_PATTERN_ORDER);
for ($x = 0; $x < sizeof($p[0]); $x++) {
if (preg_match('< p >i', $p[0][$x])) {
$strip = strip_tags($p[0][$x]);
if (preg_match("/\./", $strip))
$excerpt[] = $strip;
}
if (isset($excerpt[0])){
preg_match("/([^.]+.)/", $strip,$matches);
return $matches[1];
}
}
return false;
}
url = 'http://www.example.com/';
$content = file_get_contents($url);
$title = getMetaTitle($content);
$description = getMetaDescription($content);
$excerpt = getExcerpt($content);
print "title: $title ";
print "< br />";
print "description: $description ";
print "< br />";
print "excerpt: $excerpt";
这篇关于facebook分享链接脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文