如何从链接获取元数据


How to get metadata from a link

我希望在网站上实现一个解决方案,允许用户发布链接,一旦发布,链接将扩展内容就像在FacebookLinkedin上一样。

即"标题"、"简短描述"、"图像"。

我怎样才能做到这一点?

您可以使用PHP的函数get-meta-tags()

示例:

<?php
// Assuming the above tags are at www.example.com
$tags = get_meta_tags('http://www.example.com/');
// Notice how the keys are all lowercase now, and
// how . was replaced by _ in the key.
echo $tags['author'];       // name
echo $tags['keywords'];     // php documentation
echo $tags['description'];  // a php manual
echo $tags['geo_position']; // 49.33;-86.59
?> 

请参阅:http://php.net/manual/en/function.get-meta-tags.php

这件事背后的逻辑是在服务器上获取链接内容,查找标题和图像,然后用数据更新项目。file_get_contents将为您获取数据,您需要完成其余工作。–

如果你正在寻找具体的,有成千上万的教程。在下面找一个。

http://www.sanwebe.com/2013/06/extract-url-content-like-facebook-with-php-and-jquery