dd

PHP百度网盘直链函数

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

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