I've some problem retrieving json information with a PHP.
I've created a simple php page that returns a json:
$data = array(
'title' => 'Simple title'
);
print json_encode($data);
And in another page I try to get that array as an object:
$content = file_get_contents($url);
$json_output = json_decode($content, true);
switch(json_last_error())
{
case JSON_ERROR_DEPTH:
echo ' - Maximum stack depth exceeded';
break;
case JSON_ERROR_CTRL_CHAR:
echo ' - Unexpected control character found';
break;
case JSON_ERROR_SYNTAX:
echo ' - Syntax error, malformed JSON';
break;
case JSON_ERROR_NONE:
echo ' - No errors';
break;
}
The problem is that there is an error with this approach: I receive a "JSON_ERROR_SYNTAX" because after "file_get_contents" function I have an unknown character at the beginning of the string.
If I copy/paste it on Notepad++ I didn't see:
{"title":"Simple title"}
but I see:
?{"title":"Simple title"}
Could someone help me?