PHP实现将优酷土豆腾讯视频html地址转换成flash swf地址的方法

所属分类: 网络编程 / PHP编程 阅读数: 1648
收藏 0 赞 0 分享

本文实例讲述了PHP实现将优酷土豆腾讯视频html地址转换成flash swf地址的方法。分享给大家供大家参考,具体如下:

很多用户不知道如何复制flash地址,只能在程序中帮他们替换了:

<?php
/**
 * 支持优酷、土豆、腾讯视频html到swf转换
 */
function convert_html_to_swf($url = '')
{
  if(!is_string($url) || empty($url)) return ;
  if(strpos($url, 'swf')) return $url;
  preg_match_all('/http:\/\/(.*?)?\.(.*?)?\.com\/(.*)/', $url, $types);
  $type = $types[2][0];
  $domain = $types[1][0];
  switch ($type) {
    case 'youku' :
      preg_match_all('/http:\/\/v\.youku\.com\/v_show\/id_(.*)?\.html/', $url, $url_array);
      $swf = 'http://player.youku.com/player.php/sid/' . str_replace('/', '', $url_array[1][0]) . '/v.swf';
      break;
    case 'tudou' :
      $method = substr($types[3][0], 0, 1);
      $method = $method == 'p' ? 'v' : $method;
      preg_match_all('/http:\/\/www.tudou\.com\/(.*)?\/(.*)?/', $url, $url_array);
      $str_arr = explode('/', $url_array[1][0]);
      $count = count($str_arr);
      if ($count == 1) {
        $id = explode('.', $url_array[2][0]);
        $id = $id[0];
      } else if ($count == 2) {
        $id = $str_arr[1];
      } else if ($count == 3) {
        $id = $str_arr[2];
      }
      $swf = 'http://www.tudou.com/' . $method . '/' . $id . '/v.swf';
      break;
    case 'qq' :
      $url_array = parse_url($url);
      $swf = "http://static.video.qq.com/TPout.swf?{$url_array['query']}&auto=0";
      break;
    default :
      $swf = $url;
      break;
  }
  return $swf;
}
/**
 * 优酷视频转换测试
 * html地址 http://v.youku.com/v_show/id_XNzU4Mzg2NDA4.html?f=22720170&ev=2&from=y1.1-2.10001-0.1-2
 * swf地址 http://player.youku.com/player.php/sid/XNzU4Mzg2NDA4/v.swf
 */
echo convert_html_to_swf("http://v.youku.com/v_show/id_XNzU4Mzg2NDA4.html?f=22720170&ev=2&from=y1.1-2.10001-0.1-2");
echo "<hr>";
/**
 * 腾讯视频转换测试
 *
 * html地址 http://v.qq.com/cover/w/w5lb270k15j7ita.html?vid=v0015mnd5x6
 * swf地址 http://static.video.qq.com/TPout.swf?vid=v0015mnd5x6&auto=0
 */
echo convert_html_to_swf("http://v.qq.com/cover/w/w5lb270k15j7ita.html?vid=v0015mnd5x6");
echo "<hr>";
/**
 * 土豆视频转换测试
 *
 * html地址 http://www.tudou.com/albumplay/hqtp6W5XLN8/Kscjyz4J-RE.html
 * swf地址 http://www.tudou.com/a/hqtp6W5XLN8/&iid=132223533&resourceId=0_04_0_99/v.swf
 */
echo convert_html_to_swf("http://www.tudou.com/albumplay/hqtp6W5XLN8/Kscjyz4J-RE.html");
echo "<hr>";

PS:这里再为大家提供两款相关在线工具供大家参考使用:

迅雷、快车、旋风URL加密/解密工具:
http://tools.jb51.net/password/urlrethunder

flash版在线下载地址加密解密工具(支持迅雷/快车/旋风):
http://tools.jb51.net/password/flash_download_encode

更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP数学运算技巧总结》、《php正则表达式用法总结》、《PHP基本语法入门教程》、《PHP数组(Array)操作技巧大全》、《php字符串(string)用法总结》及《php常见数据库操作技巧汇总

希望本文所述对大家PHP程序设计有所帮助。

更多精彩内容其他人还在看

PHP Ajax实现页面无刷新发表评论

PHP Ajax实现页面无刷新发表评论
收藏 0 赞 0 分享

windows下PHP APACHE MYSQ完整配置

windows下PHP APACHE MYSQ完整配置
收藏 0 赞 0 分享

Ajax PHP分页演示

Ajax PHP分页演示
收藏 0 赞 0 分享

Smarty结合Ajax实现无刷新留言本实例

Smarty结合Ajax实现无刷新留言本实例
收藏 0 赞 0 分享

PHP 和 MySQL 开发的 8 个技巧

PHP 和 MySQL 开发的 8 个技巧
收藏 0 赞 0 分享

一个用php实现的获取URL信息的类

一个用php实现的获取URL信息的类
收藏 0 赞 0 分享

一个PHP操作Access类(PHP+ODBC+Access)

一个PHP操作Access类(PHP+ODBC+Access)
收藏 0 赞 0 分享

php你的验证码安全码?

php你的验证码安全码?
收藏 0 赞 0 分享

PHP无限分类的类

这段时间在写一个部门权限系统,需要用到无限分类技术,找了很多关于分类的代码.逐个收藏起来
收藏 0 赞 0 分享

phpwind中的数据库操作类

phpwind中的数据库操作类
收藏 0 赞 0 分享
查看更多