![](/img/trans.png)
[英]Setting up an RSS Feed (to use for podcasting with iTunes) that reads information from a mysql database (using php)
[英]Retrieving RSS Feed from iTunes using cURL and PHP
一直試圖讓一些PHP cURL代碼工作,當你給它播客網址時從iTunes獲取RSS提要。 這是代碼:
$inputString = "curl -A 'iTunes/12.1.1.4 (Windows; U; Microsoft Windows 7 Home Premium Edition Service Pack 1 (Build 7601) DPI/96' -s 'https://itunes.apple.com/podcast/id530114975'";
$input = shell_exec($inputString);
$dom = new DOMDocument();
$html = $dom->loadHTML($input);
使用shell_exec執行時的cURL調用返回空字符串。 當我調用loadHTML函數時,它會給出以下錯誤,這很明顯,因為cURL調用沒有返回任何內容.....
Warning: DOMDocument::loadHTML(): Empty string supplied as input in C:\php scripts\itunesFeedExtractor.php on line 130
現在,我從其他地方獲得了PHP cURL代碼,之前沒有使用它,並嘗試修改它以匹配我的計算機設置....我已經更改了Windows版本,Service Pack,版本號。 (不知道為什么需要DPI / 96,所以我一個人留下它)
你最好使用PHP curl擴展:
$ch = curl_init("https://itunes.apple.com/podcast/id530114975");
curl_setopt($ch, CURLOPT_USERAGENT, "iTunes/12.1.1.4 (Windows; U; Microsoft Windows 7 Home Premium Edition Service Pack 1 (Build 7601) DPI/96");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
但是如果你真的想使用shell_exec方法,請確保curl在你的路徑中 - 你可以通過從cmd / a終端運行curl命令來檢查
好吧,我通過添加更多curl_setopt()選項來實現它。 完整代碼現在為:
$ch = curl_init("https://itunes.apple.com/podcast/id530114975");
curl_setopt($ch, CURLOPT_USERAGENT, "iTunes/12.1.1.4 (Windows; U; Microsoft Windows 7 Home Premium Edition Service Pack 1 (Build 7601) DPI/96");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
干杯.....
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.