PHP中的file_get_contents无法正常工作

Sun*_*nny 1 php screen file-get-contents scrape

对于一个类项目,我们应该从另一个网站提取数据.我从GiantBomb.com选择了类似于给定游戏的游戏(在我的剧本中给予他们学分)

// $gameLink = "/call-of-duty-black-ops/61-26423/";
$html = file_get_contents("http://www.giantbomb.com" . urlencode($gameLink) . "games_similar/");
echo $html;
Run Code Online (Sandbox Code Playgroud)

这什么都不返回.

但是,如果$ gameLink是手动输入的:

$html = file_get_contents("http://www.giantbomb.com/call-of-duty-black-ops/61-26423/games_similar/");
echo $html;
Run Code Online (Sandbox Code Playgroud)

现在,它将正确返回结果.我的代码出了什么问题?我尝试urlencode()在整个链接上执行,而不仅仅是$ gameLink变量,但它仍然失败.有没有人有什么建议?

heg*_*mon 5

您只需要在html中嵌入urlencode链接.不要将urlencode链接传递给file_get_contents().