问题
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