我在尝试使用时遇到问题
file_get_contents('');
请求一个url的内容但是php不断添加
amp;
对于我尝试请求的具有 & 符号的 url 的每个部分,就像下面的一样
http:site.com/api/user.php?id=1&gender=male&tag=coolman
现在,如果我自己在浏览器中加载这个 url,它会完美运行,我可以看到内容,但是当我尝试使用上面的函数在 php 中获取内容时,它会尝试像下面那样加载 url
http:site.com/api/user.php?id=&gender=&tag=
并且因为它添加了 amp;请求每次都失败有人知道这是为什么以及我该如何阻止它吗?
最佳答案
在这种情况下,您可以使用 htmlspecialchars_decode()
<?php
$url = "http://example.com/api/user.php?id=&gender=&tag=coolman";
$url = htmlspecialchars_decode($url);
$content = file_get_contents($url);
?>
阅读更多:
http://php.net/manual/en/function.htmlspecialchars-decode.php
关于php - 当 url 有 & 时,file_get_contents 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29069175/