Back

Problem with UTF8 or Unicode


Hi guys,

In my blade templates, the following code:

<p>Österreich</p>

creates this output.

�sterreich

I use charset utf-8, that should be no problem. Any Idea how i can configure Laravel to display the Ö and other austrian chars like ä,ü...?

Thx :)

sitesense replied 4 years ago

Ensure your layout template starts something like this:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">

If the above is true, then does the "Österreich" come from the database? If that's the case, you need to ensure that your database encoding is also UTF-8.

Another point... If you use htmlentities to output data, make sure it looks like this:

htmlentities($str, ENT_QUOTES, "UTF-8");

Good luck.

Pascal1982 replied 4 years ago

Hy, also make sure that your IDE is creating your files with the current settings. Komodo edit drove me mad once on this, because it was creating the new files with the wrong charset.

mrohrboeck replied 4 years ago

Thx, but unfortunately nothing changed.

The sick thing is - the data out of the database is displayed correctly. Only the written text directly in the view file is the problem...

sitesense replied 4 years ago

mrohrboeck said:

Thx, but unfortunately nothing changed.

The sick thing is - the data out of the database is displayed correctly. Only the written text directly in the view file is the problem...

That kinda points to it being a file encoding issue.

Download Notepad++ and open your files in it. On the top menu is "Encoding" - set this to "Encode in UTF-8 without BOM" and then save the files.

moorer2k replied 4 years ago

I know this is a super old thread, but I just had this issue also. Tried what sitesense said, but for me I had to "Convert to UTF-8 without BOM" ! Finally no more symbols! Thanks for the right direction!

andersonef replied 4 years ago

I'm facing the same problem here. Is there a way to override the escape method from blade? I think blade is running htmlentities() in all my strings, but I must run htmlentities($striong, 'UTF-8') instead of. May anyone help me please?

Jsal replied 3 years ago

Sorry for bumping up old thread but I am also experiencing problems with this! Would be awesome to find a solution!

I too have done the <meta> tag thing and also I've checked my texteditor which is not the problem and has never been the problem before either. Using notepad++ and sublime.

The closest I've gotten to an answer is Blade::setEchoFormat('e(utf8_encode(%s))') but I am not sure where to put this yet!

LoveAndHappiness replied 3 years ago

same here

vascocsilva replied 3 years ago

Jsal said:

Sorry for bumping up old thread but I am also experiencing problems with this! Would be awesome to find a solution!

I too have done the <meta> tag thing and also I've checked my texteditor which is not the problem and has never been the problem before either. Using notepad++ and sublime.

The closest I've gotten to an answer is Blade::setEchoFormat('e(utf8_encode(%s))') but I am not sure where to put this yet!

I believe you need to put

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

in your app/Providers/AppServiceProvider.php file, boot method.

I had this problem with a project that uses a pre-existing mssql database, and I was bumping my head over this. I ended up finding a solution that is to put:

'characterset' => 'utf8',

instead of 'charset'=>'utf8', in database.php file, in the corresponding connection (sqlsrv) (my database has a SQL_Latin1_General_CP1_CI_AS collation).

edited

I need to add, that I was trying to understand what actually worked to solve my issue, as I tried many things, so I undid all the 'solutions', and it's working neverthless, so I'm lost again...

anand989 replied 2 years ago

My problem was solved by using:

\Blade::setEchoFormat('e(utf8_decode(%s))');

KuldeepMishra replied 2 years ago

\Blade::setEchoFormat('e(utf8_decode(%s))'); use id in app/Providers/AppServiceProvider.php file, boot method.

garimagoyal replied 2 years ago

\Blade::setEchoFormat('e(utf8_decode(%s))');

Not worked for me.

{{ trans('features.verify') }} should show Überprüfen but showing nothing

Please help

RingoStyle replied 2 years ago

Bro if you are using PHPStorm try this: File / Settings/ Editor / File Encodings select "UTF-8" on IDE Encoding y Project Encoding.

That fixed the problem. No need of \Blade::setEchoFormat('e(utf8_decode(%s))'); in my case

garimagoyal said:

\Blade::setEchoFormat('e(utf8_decode(%s))');

Not worked for me.

{{ trans('features.verify') }} should show Überprüfen but showing nothing

Please help

Roberto Espitia replied 1 year ago

I was experiencing the same problem with data from Sybase/SQLServer, and this worked for me:

  1. Configured utf8 as charset in database.cfg: ... 'charset' => 'utf8', 'collation' => 'bin_utf8', ...
  2. In the blade, encoded the parameters returned by my query: {{utf8_encode($param)}}

Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us