这是更复杂一点,但它只能得到这些链接,这是形式的真正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