這是更復雜一點,但它只能得到這些鏈接,這是形式的真正videos[0] = 'http://myvideos.com/video1.mov';
$tmp=str_replace(array("\r","\n"),'',$original,$matches);
$pattern='/\<script\>\s+var\ videos.*?((\s*videos\[\d+\]\ \=\ .http\:\/\/.*?\;\s*?)+)(.*?)\<\/script\>/';
$a=preg_match_all($pattern,$tmp,$matches);
unset($tmp);
if (!$a) die("no matches");
$pattern="/videos\[\d+\]\ \=\ /";
$matches=preg_split($pattern,$matches[1][0]);
$final=array();
while(sizeof($matches)>0) {
$match=trim(array_shift($matches));
if ($match=='') continue;
$final[]=substr($match,1,-2);
}
unset($matches);
print_r($final);
從這裏OP反饋後是簡化版本:
$original=file_get_contents($url);
$pattern='/http\:\/\/.*?\.mov/';
$a=preg_match_all($pattern,$original,$matches);
if (!$a) die("no matches");
print_r($matches[0]);
我有幾行使用file_get_contents並嘗試了幾個正則表達式。正則表達式,我不擅長。 – Nacho 2012-01-12 23:17:33