php sends/echoes '?'每个 require_once
php sends/echoes '?' for each require_once
我的 PHP 文件向某个 GET 请求发送了一个 JSON-Result。
问题是,我不断在客户端收到解析错误。查看结果字符串我发现每个结果都以几个问号(?)开头。
一点一点地削减我的脚本我发现结果包含一个 ?对于每个要求,包括 require_once 或 include_once。
奇怪的是?如果我在浏览器中 运行 请求是不可见的。但是将结果复制到文本编辑器中,它们就会变得可见。
我的服务器是 php 7.1.7
的 IIS
(简化的)代码如下所示:
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;
请求看起来像这样:
http://s-mde/itemLookup.php?number=305475
... 结果可能是这样的:
?????[{"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}]
你的文件编码是什么?从 PHP 创建对 Android 应用程序的 JSON 响应时,我遇到了类似的问题。通过使用 UTF-8、请求和响应对双方进行编码来解决它。
我的 PHP 文件向某个 GET 请求发送了一个 JSON-Result。 问题是,我不断在客户端收到解析错误。查看结果字符串我发现每个结果都以几个问号(?)开头。
一点一点地削减我的脚本我发现结果包含一个 ?对于每个要求,包括 require_once 或 include_once。 奇怪的是?如果我在浏览器中 运行 请求是不可见的。但是将结果复制到文本编辑器中,它们就会变得可见。
我的服务器是 php 7.1.7
的 IIS(简化的)代码如下所示:
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;
请求看起来像这样:
http://s-mde/itemLookup.php?number=305475
... 结果可能是这样的:
?????[{"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}]
你的文件编码是什么?从 PHP 创建对 Android 应用程序的 JSON 响应时,我遇到了类似的问题。通过使用 UTF-8、请求和响应对双方进行编码来解决它。