PHP百度网盘直链函数

jerry thinkphp 2015年11月18日 收藏
百度网盘直链函数

http://pan.baidu.com/share/link?shareid=401091&uk=3691445095
百度网盘直链函数
  1. <?php
  2. function baiduPanUrl($panUrl) {
  3.     $opts = array (
  4.             'http' => array (
  5.                     'method' => "GET",
  6.                     'timeout' => 5 
  7.             ) 
  8.     );
  9.     $context = stream_context_create ( $opts );
  10.     $html = file_get_contents ( $panUrl, false, $context );
  11.     $pattern = '/' . preg_quote ( 'http://www.baidupcs.com/file/', '/' ) . '(.*?)' . preg_quote ( '"', '/' ) . '/i';
  12.     preg_match_all ( $pattern, $html, $result );
  13.     $url = $result [1] [0];
  14.     $url = str_replace ( '&amp;', '&', $url );
  15.     return 'http://www.baidupcs.com/file/' . $url;
  16. }
  17. echo baiduPanUrl('http://pan.baidu.com/share/link?shareid=401091&uk=3691445095');