Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用cURL和PHP从iTunes检索RSS提要_Php_Ios_Curl_Rss_Itunes - Fatal编程技术网

使用cURL和PHP从iTunes检索RSS提要

使用cURL和PHP从iTunes检索RSS提要,php,ios,curl,rss,itunes,Php,Ios,Curl,Rss,Itunes,我们一直在尝试使用一些PHP cURL代码,当您提供播客URL时,这些代码可以从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'"; $inpu

我们一直在尝试使用一些PHP cURL代码,当您提供播客URL时,这些代码可以从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 terminal运行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);

干杯….

这里有一个PHP curl扩展,您最好使用它。无需shell exec curl。尝试使用php curl扩展名,如下所示,但仍然返回空字符串。想知道curl调用中的设置内容是否不正确吗?是的,我已经安装了PHP curl内容,并且找到了curl_init()函数。但它仍然像以前一样返回一个空字符串。(顺便说一句,curl是从命令行开始工作的)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”);$ch=curl_init(,CURLOPT_SSL_VERIFYHOST,0);curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0);curl_setopt($ch,CURLOPT,curl_RETURNTRANSFER,true)$response=curl\u exec($ch);看起来我通过添加两个额外的设置实现了它……新的PHP curl版本如下所示: