<?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?
Fixing "Parse error: syntax error Unexpected T_STRING error" This type of error (syntax error) usually happens because of a typo in your code, such as a missing apostrophe/quotation mark/a missing or extra space, or code that has been commented out incorrectly.
T_String is the common parse error associated with the creation of PHP files. This problem is observed when an apostrophe sign is added in between a code that has been delimited with apostrophes, generating huge conflict with the PHP document.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With