How do I get Laravel to specify my charset in all

2019-08-15 03:02发布

Yes, I know I should be using UTF-8, but I need to use windows-1252 charset encoding.

I know I can do it by hardcoding the base Synfony response class Response.php,

$charset = $this->charset ?: 'windows-1252';

but that's ugly as hell.

I can't find where to set it from the config files. Any help?

1条回答
淡お忘
2楼-- · 2019-08-15 03:41

You can change charset in the middleware:

<?php namespace App\Http\Middleware;

use Closure;

class SetCharset
{
    public function handle($request, Closure $next)
    {
        $response = $next($request);
        $response->header('Content-Type', 'text/html; charset=windows-1252');

        return $response;
    }
}

Just make sure that all the content you return is in proper encoding.

查看更多
登录 后发表回答