如何从 link 获取元数据
How to get metadata from a link
我希望在一个网站上实施一个解决方案,允许用户 post link 一次 posted例如,link 将 扩展内容 ,就像在 Facebook 或 Linkedin 上一样。
即'Title'、'Short Description'、'Image'。
我怎样才能做到这一点?
背后的逻辑是在您的服务器上获取 link 内容并查找标题和图像,然后使用数据更新您的项目。 file_get_contents 将为您获取数据,您需要完成剩下的工作。 –
如果你要找具体的,这里有成千上万的教程。在下面找到一个。
http://www.sanwebe.com/2013/06/extract-url-content-like-facebook-with-php-and-jquery
您可以为此使用 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
?>
我希望在一个网站上实施一个解决方案,允许用户 post link 一次 posted例如,link 将 扩展内容 ,就像在 Facebook 或 Linkedin 上一样。
即'Title'、'Short Description'、'Image'。
我怎样才能做到这一点?
背后的逻辑是在您的服务器上获取 link 内容并查找标题和图像,然后使用数据更新您的项目。 file_get_contents 将为您获取数据,您需要完成剩下的工作。 –
如果你要找具体的,这里有成千上万的教程。在下面找到一个。
http://www.sanwebe.com/2013/06/extract-url-content-like-facebook-with-php-and-jquery
您可以为此使用 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
?>