【发布时间】:2013-06-25 00:31:52
【问题描述】:
我是php新手
我需要从同一页面获得两个结果。 og:image 和 og:video
这是我当前的代码
preg_match('/property="og:video" content="(.*?)"/', file_get_contents($url), $matchesVideo);
preg_match('/property="og:image" content="(.*?)"/', file_get_contents($url), $matchesThumb);
$videoID = ($matchesVideo[1]) ? $matchesVideo[1] : false;
$videoThumb = ($matchesThumb[1]) ? $matchesThumb[1] : false;
有没有办法在不复制我的代码的情况下执行相同的操作
【问题讨论】:
-
当然,把file_get_contents的结果赋值给一个变量。
-
但是你必须做两次 preg_match,因为它不是同一个操作。但是是的,
$content = file_get_contents($url);会节省很多时间
标签: php preg-match file-get-contents