了解知识
 
  1. <?php 
  2. /** 
  3.  * 支持优酷、土豆、腾讯视频html到swf转换 
  4.  * @link http://www.phpddt.com 
  5.  */ 
  6. function convert_html_to_swf($url = '')  
  7.     if(!is_string($url) || emptyempty($url)) return ; 
  8.     if(strpos($url'swf')) return $url
  9.      
  10.     preg_match_all('/http:\/\/(.*?)?\.(.*?)?\.com\/(.*)/'$url$types); 
  11.     $type = $types[2][0]; 
  12.     $domain = $types[1][0]; 
  13.   
  14.     switch ($type) { 
  15.         case 'youku' : 
  16.             preg_match_all('/http:\/\/v\.youku\.com\/v_show\/id_(.*)?\.html/'$url$url_array); 
  17.             $swf = 'http://player.youku.com/player.php/sid/' . str_replace('/'''$url_array[1][0]) . '/v.swf'
  18.             break
  19.          
  20.         case 'tudou' : 
  21.             $method = substr($types[3][0], 0, 1); 
  22.             $method = $method == 'p' ? 'v' : $method
  23.             preg_match_all('/http:\/\/www.tudou\.com\/(.*)?\/(.*)?/'$url$url_array); 
  24.             $str_arr = explode('/'$url_array[1][0]); 
  25.             $count = count($str_arr); 
  26.              
  27.             if ($count == 1) { 
  28.                 $id = explode('.'$url_array[2][0]); 
  29.                 $id = $id[0]; 
  30.             } else if ($count == 2) { 
  31.                 $id = $str_arr[1]; 
  32.             } else if ($count == 3) { 
  33.                 $id = $str_arr[2]; 
  34.             } 
  35.              
  36.             $swf = 'http://www.tudou.com/' . $method . '/' . $id . '/v.swf'
  37.             break
  38.              
  39.         case 'qq' : 
  40.             $url_array = parse_url($url); 
  41.             $swf = "http://static.video.qq.com/TPout.swf?{$url_array['query']}&auto=0"
  42.             break
  43.   
  44.         default : 
  45.             $swf = $url
  46.             break
  47.     } 
  48.     return $swf
  49.   
  50.   
  51. /** 
  52.  * 优酷视频转换测试 
  53.  * html地址  http://v.youku.com/v_show/id_XNzU4Mzg2NDA4.html?f=22720170&ev=2&from=y1.1-2.10001-0.1-2 
  54.  * swf地址 http://player.youku.com/player.php/sid/XNzU4Mzg2NDA4/v.swf 
  55.  */ 
  56.   
  57. 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"); 
  58. echo "<hr>"
  59.   
  60. /** 
  61.  * 腾讯视频转换测试 
  62.  *  
  63.  * html地址 http://v.qq.com/cover/w/w5lb270k15j7ita.html?vid=v0015mnd5x6 
  64.  * swf地址 http://static.video.qq.com/TPout.swf?vid=v0015mnd5x6&auto=0 
  65.  */ 
  66.   
  67. echo convert_html_to_swf("http://v.qq.com/cover/w/w5lb270k15j7ita.html?vid=v0015mnd5x6"); 
  68. echo "<hr>"
  69.   
  70. /** 
  71.  * 土豆视频转换测试 
  72.  *  
  73.  * html地址 http://www.tudou.com/albumplay/hqtp6W5XLN8/Kscjyz4J-RE.html 
  74.  * swf地址  http://www.tudou.com/a/hqtp6W5XLN8/&iid=132223533&resourceId=0_04_0_99/v.swf 
  75.  */ 
  76.   
  77. echo convert_html_to_swf("http://www.tudou.com/albumplay/hqtp6W5XLN8/Kscjyz4J-RE.html"); 
  78. echo "<hr>"
标签: PHP 源码
扩展知识