2017-11-25 100 views
0

我有這下面的PHP腳本。我想用curl添加調用函數。 如何在我的下面的腳本上寫入捲曲?如何將curl寫入php?

我是編程新手。我仍然很好地學習它。請檢查我的代碼並嘗試幫助我添加捲曲。

我的腳本沒有錯誤。只是我想添加php函數替換爲curl函數。

我希望如此,你明白。對不起,我的英語不好。感謝

我的代碼是在這裏:

$url = 'https://web.facebook.com/'.$pageid.'/videos/'.$id.'/'; 

$context = [ 
    'http' => [ 
     'method' => 'GET', 
     'header' => "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.47 Safari/537.36", 
    ], 
]; 
$context = stream_context_create($context); 
$data = file_get_contents($url, false, $context); 

function cleanStr($str) 
{ 
    return html_entity_decode(strip_tags($str), ENT_QUOTES, 'UTF-8'); 
} 

function hd_finallink($curl_content) 
{ 

    $regex = '/hd_src_no_ratelimit:"([^"]+)"/'; 
    if (preg_match($regex, $curl_content, $match)) { 
     return $match[1]; 

    } else {return;} 
} 

function sd_finallink($curl_content) 
{ 

    $regex = '/sd_src_no_ratelimit:"([^"]+)"/'; 
    if (preg_match($regex, $curl_content, $match1)) { 
     return $match1[1]; 

    } else {return;} 
} 


$hdlink = hd_finallink($data); 
$sdlink = sd_finallink($data); 

if ($sdlink || $hdlink) { 

echo '<a href="'.$hdlink.'" download="hd.mp4" class="link">HD Download </a>'; 
echo '<a href="'.$sdlink.'" download="sd.mp4" class="link">SD Download </a>'; 

} else { 

echo 'Download not showing - Please Reload This Page'; 

} 

回答

1

之前,我們可以用捲曲的要求做任何事情,我們需要首先實例捲曲的一個實例 - 我們可以通過調用函數做到這一點curl_init();

對於GET請求示例代碼:用於POST

// Get cURL resource 
$curl = curl_init(); 
// Set some options - we are passing in a useragent too here 
curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1, 
    CURLOPT_URL => 'http://testcURL.com/?item1=value&item2=value2', 
    CURLOPT_USERAGENT => 'Codular Sample cURL Request' 
)); 
// Send the request & save response to $resp 
$resp = curl_exec($curl); 
// Close request to clear up some resources 
curl_close($curl); 

示例代碼熱曲斯:

// Get cURL resource 
$curl = curl_init(); 
// Set some options - we are passing in a useragent too here 
curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1, 
    CURLOPT_URL => 'http://testcURL.com', 
    CURLOPT_USERAGENT => 'Codular Sample cURL Request', 
    CURLOPT_POST => 1, 
    CURLOPT_POSTFIELDS => array(
     item1 => 'value', 
     item2 => 'value2' 
    ) 
)); 
// Send the request & save response to $resp 
$resp = curl_exec($curl); 
// Close request to clear up some resources 
curl_close($curl); 

See this link

+0

怎麼我把它替換到我的PHP。請用完整的代碼更新您的代碼。謝謝 –

+0

'$ resp = shell_exec('curl -s -d item1 = value -d item2 = value2 http://testcURL.com');'' – hanshenrik