3

I have a very simple bit of code

$pc1 = $_POST['post_code1'];
$pc2 = $_POST['post_code2'];
$url = "http://maps.google.com/maps/nav?q=from:".$pc1."%20to:".$pc2;
$url_data = file_get_contents($url);
$json_data = json_decode($url_data);
var_dump($json_data);

$url_data is full of juicy json stuff but $json_data returns NULL. Does anyone have an idea why?

Robert Johnstone
  • 5,431
  • 12
  • 58
  • 88

1 Answers1

3

I found the following worked after find a number of people with similar problems

$json_data = json_decode(utf8_encode($url_data),true);

source

Community
  • 1
  • 1
Robert Johnstone
  • 5,431
  • 12
  • 58
  • 88