PHP JSON标题在输出之前添加换行符

时间:2015-05-19 14:16:01

标签: php json codeigniter http-headers homestead

我最近遇到了一个问题,当我使用PHP header()命令时,它会在显示输出之前在命令之后添加换行符。

我正在使用CodeIgniter 2.2.2以及来自https://github.com/chriskacerguis/codeigniter-restserver的较旧版本的CodeIgniter Rest Controller。我使用PHP 5.6.8在XAMPP的Apache开发环境中运行。这个问题似乎已经开始了,当我为了我的环境移动到Laravel Homestead时,在带有nginx的Ubuntu上运行PHP 5.6.7。

以下是直接来自REST_Controller文件的代码示例:

header('Content-Type: '. $this->_supported_formats[$this->response->format] . '; charset=' . strtolower($this->config->item('charset')));
$output = $this->format->factory($data)->{'to_'.$this->response->format}();

没有标题行,它工作正常,但是,它将内容类型设置为text / html而不是application / json。

0 个答案:

没有答案