简体   繁体   中英

Unicode characters (emojis) from MySQL displayed as “????”

On a MySQL table, the column release_notes is encoded in utf8mb4.

On the Laravel config/database.php file, the following is under the MySQL section:

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

From a MySQL client, I set the value of that column to an emoji (eg "📌"). It is properly displayed on the MySQL client.

To display that column, on the Blade template I have the following:

{!! nl2br($app->release_notes) !!}

However, what ends up displaying on the browser is:

????

To verify this is not a browser/HTML problem, I hardcoded the emoji directly on the template file and it is displayed as expected.

I did try the accepted answer of this question , to no avail.

What am I missing?

Exactly 4 question marks? The Emoji is 4 bytes long. The likely cause is trying to transform non-latin1 characters into a CHARACTER SET latin1 column.

Check all these:

  • The column(s) in the database -- Use SHOW CREATE TABLE to verify that they are explicitly set to utf8, or defaulted from the table definition. (It is not enough to change the database default .)
  • The connection between the client and the server. See SET NAMES utf8 .
  • The bytes you have. (This is probably the case.)
  • If you are displaying the text in a web page, check the <meta> tag.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM