Home  >  Article  >  Backend Development  >  使用PHP提取视频网站页面中的FLASH地址的代码_PHP

使用PHP提取视频网站页面中的FLASH地址的代码_PHP

WBOY
WBOYOriginal
2016-06-01 12:19:53812browse

然后我用PHP实现了这个功能,我觉得用PHP来做这项工作简直是一种享受!使用其提供的强大的HTML页面处理函数和正则表达式,短短的几行代码就能搞定这个功能。
贴一下关键代码:
复制代码 代码如下:
//获取优酷页面中的flash地址
function get_flash_url( $url )
{
$lines = file($url);
foreach ($lines as $linenum=> $line) {
preg_match_all('||',$line,$result);
$swfurl=$result[1][0];
if(!empty($swfurl))
return $swfurl;
}
}
?>
$url=$_SERVER["QUERY_STRING"];
$flashurl= get_flash_url($url);
echo ( $flashurl );
?>

比如这个文件我们存为 test.php,那么我们只需要运行 test.php?优酷视频的url 就可以解析出FLASH地址了。
思路很简单,就是先看看优酷视频网页的HTML代码里关键FLASH地址那段的特征。随便找个网页,比如我们可以看到这一段:

flash地址:
然后使用正则表达式来将其中的地址段匹配掉,就OK了。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn