我想在我的网站上使用bit.ly。当我这样做时:
$short_url = json_decode(file_get_contents("http://api.bit.ly/v3/shorten?login=myLogin&apiKey=myApiKey&longUrl=".urlencode("http://example.com")."&format=json"))->data->url;
工作正常。
但是当我尝试将链接放在变量中时。
$link = 'http://example.com';
$short_url = json_decode(file_get_contents("http://api.bit.ly/v3/shorten?login=myLogin&apiKey=myApiKey&longUrl=".urlencode(**$link**)."&format=json"))->data->url;
它不起作用。任何帮助将不胜感激。
答案 0 :(得分:1)
file_get_contents()
的输出是什么。你可以这样做:var_dump(file_get_contents("http://api.bit.ly/v3/shorten?login=myLogin&apiKey=myApiKey&longUrl=".urlencode($link)."&format=json"));
如果那里有良好的输出,请检查并将其传递给json_encode()
。