我是新手到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);'會節省很多次 –