My PHP file sends a JSON-Result to some GET-Request. The problem is, that I keep getting parsing errors on the client side. Looking at the result string I found that each result starts with several question marks (?).
Cutting my scripts down bit by bit I found that the result contains one ? for each require, include, require_once or include_once. Strangely the ? are invisible if I run the request in a browser. But copying the result into a text editor they become visible.
My server is an IIS with php 7.1.7
The (simplified) code looks something like this:
lookup.php
<?php
include_once 'common/server.php';
echo $srv->QueryTable(qry_ItemList);
server.php
<?php
require_once 'constants.php';
require_once 'sql/queryNAV.php';
class JSON_Server
{
public function QueryTable($SQLTextName)
{
$qry_result = /*(do SQL-Query)*/;
return json_encode($qry_result);
}
}
$srv = new JSON_RESTServer;
The request looks something like this:
http://s-mde/itemLookup.php?number=305475
... and the result might be something like this:
?????[{"Typ":"I","No_":"408835","Description":"Ds Scene it? Twilight","debugCounter":96},{"Typ":"L","No_":"100773","Description":"Axe Deo Roll Diverse 50ml Ro","debugCounter":96},{"Typ":"L","No_":"410296","Description":"Axe Duschgel Africa 250ml Fl.","debugCounter":96},{"Typ":"L","No_":"102939","Description":"Axe Duschgel Alaska 250ml Fl.","debugCounter":96},{"Typ":"L","No_":"408835","Description":"Ds Scene it? Twilight","debugCounter":96},{"Typ":"L","No_":"100332","Description":"Rexona Roll On Men Sport 50ml","debugCounter":96}]
What is your file encoding? I've had similar problems while creating JSON responses to Android app from PHP. Solved it by encoding both sides with UTF-8, request and response.