title: PHP - get json data from url
body: <p>I'm trying to load json data from this url =
  <a href="http://api.opencagedata.com/geocode/v1/json?query=48.84737%2C2.28605&amp;pretty=1&amp;no_annotations=1&amp;no_dedupe=1&amp;key=b61388b5a248b7cfcaa9579ed290485b" rel="nofollow">http://api.opencagedata.com/geocode/v1/json?query=48.84737%2C2.28605&amp;pretty=1&amp;no_annotations=1&amp;no_dedupe=1&amp;key=b61388b5a248b7cfcaa9579ed290485b</a></p>
  
  <p>Using file_get_contents works with other json urls but this one is strange. It returns only "{" the first line. Strlen gives 1480 which is right.Substr(2,18) gives "documentation" which is right too. But still i can't echo the entire text. Maybe there's some way to read the text line by line and save it in another string ? The entire text is still fully loaded in the textfile
  Here's the php code i tried</p>
  
  <pre><code>&lt;?php
  $url = file_get_contents("http://api.opencagedata.com/geocode/v1/json?query=48.84737%2C2.28605&amp;pretty=1&amp;no_annotations=1&amp;no_dedupe=1&amp;key=b61388b5a248b7cfcaa9579ed290485b");
  $save = file_put_contents("filename.txt", $url);
  echo $url;
  ?&gt;
  </code></pre>
  
  <p>Also tried this function but still same.</p>
  
  <pre><code>function get_data($url) {
   $ch = curl_init();
   $timeout = 5;
   curl_setopt($ch, CURLOPT_URL, $url);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
   $data = curl_exec($ch);
   curl_close($ch);
   return $data;
  }
  </code></pre>