Reputation: 421
<?php
include_once 'forecastVo.php';
include_once 'BaseVo.php';
$count=0;
$json_url = file_get_contents(
'http://maps.google.com/maps/api/geocode/json' .
'?address='jaipur'&sensor=false'); //line 9
if($json_url){
$obj = json_decode($json_url,true);
$obj2= $obj['results'];
}
?>
I am getting an error:
Parse error: syntax error, unexpected T_STRING in /home/a4101275/public_html/index.php on line 9
line 9 is where I am using the file_get_contents
.
What does the error mean and how do I fix it?
Upvotes: 6
Views: 91108
Reputation: 19539
Why quote it at all? I can't imagine the Google API requires (or even expects) that value to be quoted.
$json_url = file_get_contents('http://maps.google.com/maps/api/geocode/json?address=jaipur&sensor=false'); //line 9
Or, is jaipur
a variable? If so:
$json_url = file_get_contents("http://maps.google.com/maps/api/geocode/json?address=$jaipur&sensor=false"); //line 9
Hard to tell from your question what it is you're trying to accomplish...
Upvotes: 2
Reputation: 6767
$json_url = file_get_contents("http://maps.google.com/maps/api/geocode/json?address='jaipur'&sensor=false");
Or escaping it with \
Upvotes: 1
Reputation: 7040
You have to use your escape characters correctly. You can't have a single-quote ('
) inside of a single-quote-encapsulated string. It breaks it. In order to continue the string and have PHP interpret your inner single-quote literally, you have to escape it with \
.
$json_url = file_get_contents('http://maps.google.com/maps/api/geocode/json?address=\'jaipur\'&sensor=false');
Or you can use the alternative string encapsulator, double-quote ("
).
$json_url = file_get_contents("http://maps.google.com/maps/api/geocode/json?address='jaipur'&sensor=false");
For future reference, Parse error: syntax error, unexpected T_STRING
usually means you have a bad string somewhere on that line.
Upvotes: 7