bit.ly dynamic link php
문제
I am trying to use bit.ly in my website. When I do this:
$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;
It works fine.
However when I try placing the link in a variable.
$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;
It does not work. Any help would be appreciated.
해결책
Check what is the output of file_get_contents()
. You can do it this way:
var_dump(file_get_contents("http://api.bit.ly/v3/shorten?login=myLogin&apiKey=myApiKey&longUrl=".urlencode($link)."&format=json"));
If there's a good output there, check and then pass it to json_encode()
.
제휴하지 않습니다 StackOverflow