我是新手到php得到两个结果不重复preg_match和file_get_contents
而且我需要从同一页得到两个结果。 OG:图片和og:视频
这是我当前的代码
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的结果分配给一个变量。 – datasage
但你必须做两次preg_match,因为它不是相同的操作。但是,做'$ content = file_get_contents($ url);'会节省很多次 –