Pierre Ftn
Pierre Ftn

Reputation: 331

Utf8 encoding issue with Laravel

I have an issue after deploying my laravel website ( that works properly in local ). Some text are not encoded correctly, for example : what should be Joël is Joël

Some information :

Would you have any idea to solve my problem ?

Upvotes: 6

Views: 16951

Answers (3)

Sandeep Sherpur
Sandeep Sherpur

Reputation: 2802

I just removed charset from config/database.php file. Now Its working fine for me.

        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',

Upvotes: 0

Pierre Ftn
Pierre Ftn

Reputation: 331

I found a solution :

I use

{!! htmlentities($variable, ENT_QUOTES, "UTF-8") !!}

But it's not convenient ...

I tried :

Blade::setEchoFormat('e(htmlentities(%s,ENT_QUOTES,'UTF-8'))');

in AppServiceProvider but it doesn't solve the problem.

So it's a temporary solution ...

Upvotes: 2

MD. Jubair Mizan
MD. Jubair Mizan

Reputation: 1570

Just do this in a Service Provider AppServiceProvider and put into boot method

Blade::setEchoFormat('e(utf8_encode(%s))');

Generally sticking to UTF-8 keeps life simple.

Be super careful copying and pasting from anywhere else into your code - basically always go through Notepad++ and use its convert to UTF-8 (without BOM) before copying and pasting into your code.

Then make sure all your views (including error pages), have

<meta charset="UTF-8">

Or the following if you're doing HTML4

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">

Hope this will help you

Upvotes: 3

Related Questions