PHP JSON header adding a line break before output

北城以北 提交于 2019-12-24 04:46:09

问题


I recently started having a problem where when I use the PHP header() command, it is adding a line-break after the command before the output is displayed.

I am using CodeIgniter 2.2.2 and a slightly older version of the CodeIgniter Rest Controller from https://github.com/chriskacerguis/codeigniter-restserver. I was running on an Apache development environment with XAMPP using PHP 5.6.8. The issue seems to have started when I moved to Laravel Homestead for my environment which has PHP 5.6.7 running on Ubuntu with nginx.

Here is a sample of the code straight from the REST_Controller file:

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

Without the header line, it works fine, however, it is setting the content type to text/html instead of application/json.

来源:https://stackoverflow.com/questions/30328215/php-json-header-adding-a-line-break-before-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!