我正在使用 file_get_contents 从任何 url 获取 og:image。
$fooURL = file_get_contents($URLVF['url']);
然后我过滤 property=og:image 从页面中获取图像,下面的代码适用于大多数网站
preg_match("/content='(.*?)' property='og:image'/", $fooURL, $fooImage);
但是像 www.howcast.com 这样的网站有 og:image 的不同代码,如下所示
<meta content='http://attachments-mothership-production.s3.amazonaws.com/images/main-avatar.jpeg' property='og:image'>
因此,要获取上述代码的图像链接,我需要 preg_match 是这样的
preg_match('/property="og:image" content="(.*?)"/', $fooURL, $fooImage);
但是当然,如果我现在使用上面的代码,唯一可以工作的网站就是howcast,其他所有网站都不会返回任何内容
知道如何使代码使用编写元代码的任何方法或任何替代方法来顺利获取图像链接