2014-09-29 111 views
0

能否請你幫我捲曲PHP speakerdeck.com透過oEmbed URL如何捲曲PHP SpeakerDeck.com透過oEmbed URL

我嘗試這樣做,但它返回任何東西。

<?php 
$url='https://speakerdeck.com/oembed.json?url=http://www.speakerdeck.com/addyosmani/css-performance-tooling'; 
function get_data($url){ 
     $curl = curl_init(); 
     curl_setopt($curl, CURLOPT_URL, $url); 
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
     curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16"); 
     $curlData = curl_exec($curl); 
     curl_close($curl); 
     return $curlData; 
    } 


get_data($url); 
?> 
+0

編輯你的問題是好的,但完全改變它意味着人們試圖幫助你需要重新調試一遍。 – user1269942 2014-09-29 17:28:49

+0

試試echo get_data($ url);在底部。 – user1269942 2014-09-29 17:29:43

回答

1

您的代碼正在爲我工​​作。也許你的問題應該更清楚。你的意思是你想抓取網頁的內容?

這個作品,如果你想抓住的HTTP返回代碼(代碼):

$url='https://speakerdeck.com/oembed.json?url=http://www.speakerdeck.com/addyosmani/css-performance-tooling'; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_HEADER, TRUE); 
curl_setopt($ch, CURLOPT_NOBODY, TRUE); // remove body 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
$head = curl_exec($ch); 
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
print_r($httpCode); 
curl_close($ch); 

,如果你想的網頁內容:

$url='https://speakerdeck.com/oembed.json?url=http://www.speakerdeck.com/addyosmani/css-performance-tooling'; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_HEADER, TRUE); 
//curl_setopt($ch, CURLOPT_NOBODY, TRUE); // remove body 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
$page = curl_exec($ch); 
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
//you can do some error checking if you want here. 
print_r($page); 
curl_close($ch); 

爲您的新代碼:

get_data($url); 

試試看:

echo get_data($url); 
+0

對我來說沒有任何反應,上面的代碼返回0 – Egglabs 2014-09-29 17:22:33

+0

我複製粘貼確切的代碼,我得到一個迴應。你編輯或複製粘貼? – user1269942 2014-09-29 17:25:37

+0

1)確保註釋行。 2)捕獲curl_exec返回3)print_r正確的變量(curl_exec返回) – user1269942 2014-09-29 17:26:53