2014-03-01 29 views
-3

請得到「SHORTURL」參數 不起作用get_file_contents得到JSON參數

  $json_string = file_get_contents('http://ow.ly/api/1.1/url/shorten?apiKey=APICODE&longUrl=' . urlencode($url)); 
     $json = json_decode($json_string, true); 

     $shorten=$json['shortUrl']; 
+0

你想做什麼? –

+0

你可以顯示$ json_string的值嗎? – lwitzel

+0

$ url =「blabla.com」; – user3369359

回答

0

如果你真的看響應從ow.ly你會看到,它是:

{"results":{"hash":"3hGIhh","longUrl":"http:\/\/www.stackoverflow.com","shortUrl":"http:\/\/ow.ly\/3hGIhh"}} 

所以你需要做到以下幾點:

$shortUrl = $json->results->shortUrl; 

或可能

$shortUrl = $json['results']['shortUrl'];