Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
<?php
include_once 'forecastVo.php';
include_once 'BaseVo.php';
//ini_set("display_errors", 0);
    // The value of the variable name is found
    $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 developing an application where i need to get the latitude and longitude for a location.

Uptil now this code was working fine..

but now i am getting the 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 file_get_contents

i tried googling about the same error but could not find a solution? what might be wrong with this?

share|improve this question
You have to use your escape characters correctly. – Matt Aug 2 '12 at 20:12

3 Answers

up vote 2 down vote accepted

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.

share|improve this answer

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...

share|improve this answer
$json_url = file_get_contents("http://maps.google.com/maps/api/geocode/json?address='jaipur'&sensor=false");

Or escaping it with \

share|improve this answer
thanks it works now – shiven Aug 2 '12 at 20:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.