我有一个这样的url:
http://r16---sn-4g57kn6e.googlevideo.com/videoplayback?&quality=medium&signature=797C0FEB1961E6226294D5FC19BC0CD28657975C.1E745D852200D14B706F0EBF9EA8762680374564&itag=43&mv=m&ip=84.19.165.220&ipbits=0&ms=au&ratebypass=yes&source=youtube&mt=1390347607&id=8b92b07ff9cd9862&key=yt5&fexp=942502,916626,929305,936112,924616,936910,936913,907231,921090&upn=cMPazwtmyZU&sver=3&sparams=id,ip,ipbits,itag,ratebypass,source,upn,expire&expire=1390371882&type=video%2Fwebm%3B+codecs%3D%22vp8.0%2C+vorbis%22&fallback_host=tc.v12.cache5.googlevideo.com&title=Requiem+For+A+Dream+Original+Song&title=Requiem For A Dream Original Song问题是readfile()函数会产生特殊字符(错误请求)的错误原因。
如果我使用urlencode(),它会进一步破坏url。
我该怎么处理呢?
发布于 2014-01-22 08:09:07
您只需在查询字符串中使用urlencode()数据即可。在你的帖子中,你没有逃脱最后一个变量。请勿urlencode()整个URL。这是不恰当的。
梦想原创歌曲的http://r16---sn-4g57kn6e.googlevideo.com/videoplayback?&quality=medium&signature=797C0FEB1961E6226294D5FC19BC0CD28657975C.1E745D852200D14B706F0EBF9EA8762680374564&itag=43&mv=m&ip=84.19.165.220&ipbits=0&ms=au&ratebypass=yes&source=youtube&mt=1390347607&id=8b92b07ff9cd9862&key=yt5&fexp=942502,916626,929305,936112,924616,936910,936913,907231,921090&upn=cMPazwtmyZU&sver=3&sparams=id,ip,ipbits,itag,ratebypass,source,upn,expire&expire=1390371882&type=video%2Fwebm%3B+codecs%3D%22vp8.0%2C+vorbis%22&fallback_host=tc.v12.cache5.googlevideo.com&title=Requiem+For+A+Dream+Original+Song&title=Requiem
我只会使用http_build_query()。
echo 'http://r16---sn-etc' . http_build_query(array(
'ip' => 84.19.165.220,
'ipbits' => 0,
// etc.
'title' => 'Requiem for a Dream'
));发布于 2014-01-22 08:08:52
结合我在原始答案中的内容,再加上Brad的答案中的一些想法,我提供了以下解决方案
<?php
$url='http://r16---sn-4g57kn6e.googlevideo.com/videoplayback?&quality=medium&signature=797C0FEB1961E6226294D5FC19BC0CD28657975C.1E745D852200D14B706F0EBF9EA8762680374564&itag=43&mv=m&ip=84.19.165.220&ipbits=0&ms=au&ratebypass=yes&source=youtube&mt=1390347607&id=8b92b07ff9cd9862&key=yt5&fexp=942502,916626,929305,936112,924616,936910,936913,907231,921090&upn=cMPazwtmyZU&sver=3&sparams=id,ip,ipbits,itag,ratebypass,source,upn,expire&expire=1390371882&type=video%2Fwebm%3B+codecs%3D%22vp8.0%2C+vorbis%22&fallback_host=tc.v12.cache5.googlevideo.com&title=Requiem+For+A+Dream+Original+Song&title=Requiem For A Dream Original Song';
$cleanUrl = parseQuery($url);
$data = getData($cleanUrl);
echo "file read in OK\n";
function parseQuery($url) {
preg_match('/(https?:\/\/[^?]+\?)(.*)$/', $url, $rawQuery);
preg_match_all('/([^=]+)=([^&]+)&/', $rawQuery[2], $queries);
$qArray = array_combine($queries[1], $queries[2]);
$newUrl = $rawQuery[1] . http_build_query($qArray);
return $newUrl;
}
function getData($url) {
$useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_USERAGENT, $useragent);
$data = curl_exec($curl);
curl_close($curl);
return $data;
}
?>这主要涉及以下几个步骤:
?之前的东西”和“&")readfile()).“)。然后,使用(根据Brad的回答)=之前的所有数组组合成一个有效的查询字符串。我使用http_build_query curl来获取文件(只是因为我比just更了解它
它似乎对我很有效。如果对你不起作用,请告诉我。
https://stackoverflow.com/questions/21271540
复制相似问题