发布共享链接时,如何抓取标题+链接的图像 [英] How to grab the title + images of a link when posting sharing a link
问题描述
我想知道如何在PHP中复制Facebook上的comportment:
I was wondering how to reproduce in PHP the comportment on Facebook:
当您共享链接时,它会抓住该页面的标题,并自动抓取
When you share a link, it grabs the title of the page, and it automatically grabs the images from the page to decorate the link.
有没有像插件一样可以看一下?
Is there anything already done like a plugin i can take a look at ?
谢谢。
推荐答案
使用PHP DOM类拉取url内容并解析html以先抓取< img>
url和< h1>
文本
use PHP DOM classes to pull url content and parse the html to grab first <img>
url and <h1>
text.
更新
使用DOM loadHTMLFile方法将文件加载到DOMDocument对象中。
use the DOM loadHTMLFile method to load the file into a DOMDocument object.
http://www.php.net/manual/en/domdocument.loadhtmlfile .php
使用DOM getELementsByTagName方法获取节点内容。
use the DOM getELementsByTagName method to get the node contents.
http://www.php.net/manual/en/domdocument.getelementsbytagname.php
使用nodeValue方法获取节点的值
use nodeValue method to get the node's value
这篇关于发布共享链接时,如何抓取标题+链接的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!