Join the Stack Overflow Community
Stack Overflow is a community of 6.5 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up
<?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?

share|improve this question
    
You have to use your escape characters correctly. – Matt Aug 2 '12 at 20:12
    
You can get this error for many different reasons 1: forget a semicolon on a previous line, 2: forget a concatenation operator dot . between variables, or like in your case, 3: delimit a string using single quotes which contain single quotes. The interior single quotes are treated as delimiters and complete the string. The PHP parser sees the word after it as a syntax error. As matt said above, your interior single quotes need to be properly escaped with a \'in order to be interpreted as literals rather than delimiters. – Eric Leschinski Oct 27 at 20:17
up vote 3 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.