社区首页 >问答首页 >如何在url中停止将&更改为&?问如何在url中停止将&更改为&?ENStack Overflow用户提问于 2017-01-16 01:35:50回答 2查看 1.9K关注 0票数 0我有一个像这样的url,https://www.example.com/send?id=1&text=http://example2.com/song.mp3
当我尝试使用file_get_contents()获取url的数据时,它显示以下错误,
PHP警告: file_get_contents(https://www.example.com/send?id=1&text=http://example2.com/song.mp3):无法打开流: HTTP请求失败!HTTP/1.1 501未实现
和&已转换为&。由于url不起作用。
我在&上尝试了htmlspecialchars_decode()和preg_replace(),但它什么也没做。
如何解决这个问题?
phpurlhtmlspecialchars关注问题分享EN回答 2推荐最新Stack Overflow用户发布于 2017-01-16 02:27:04
我认为你最好使用cURL而不是file_get_contents(),因为引用服务器必须在他们的服务器中启用allow_url_fopen,如果你使用的是file_get_contents(),但cURL是一个库,它只是发出一个http请求
代码语言:javascript复制
$cSession = curl_init();
curl_setopt($cSession,CURLOPT_URL,"https://www.example.com/send?id=1&text=http://example2.com/song.mp3");
curl_setopt($cSession,CURLOPT_RETURNTRANSFER,true);
curl_setopt($cSession,CURLOPT_HEADER, false);
$result=curl_exec($cSession);
curl_close($cSession);
echo $result;
?> 请参考以下链接
file_get_contents script works with some websites but not others
cURL vs file_get_contents
收藏分享票数 1ENStack Overflow用户发布于 2018-05-07 14:14:41
看看这个,先生,在哪里$str=“你的链接”
示例
代码语言:javascript复制$str = "https://www.example.com/send?id=1&text=http://example2.com/song.mp3";
echo html_entity_decode($str);将输出您想要的文件....
收藏分享票数 0EN页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持原文链接:https://stackoverflow.com/questions/41664174
复制相关文章