Parse error: syntax error, unexpected T_STRING in php

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.

Leave a Comment