1

I have a table called mh_country. Here is one row from phpmyadmin. You can see that emoji correctly displays the flag of Afghanistan.

snapshot of database to get emoji

The encoding in mysql of 'emoji' is correct and is as follows;

mysql structure of emoji

I would like to display the emoji in my view. First of all, here is my method to get 'emoji':

function display_country_dialing_codes(){
    $model = new \App\Models\MhCountryModel;
    $builder = $model->builder('mh_country');
    $builder->select('country_name, phonecode, emoji');
    $query   = $builder->get();
    $result  = $query->getResult();
    return $result;
}

Now I am trying to display the flag in my view with;

            $x = display_country_dialing_codes();
            echo $x[0]->emoji;

but all I get is '??'.

How can I display the emoji flag please?

Vickel
  • 7,879
  • 6
  • 35
  • 56
spreaderman
  • 918
  • 2
  • 10
  • 39

1 Answers1

1

Update

As of Jan 2022 browsers except Firefox do not support country flag emojis. Most of the other emojis are displayed properly.

Original Answer

Tested and it works

enter image description here

Edit your database config file

app\Config\Database.php

and set charset to utf8mb4 under your database connection

'charset'  => 'utf8mb4',
Ergec
  • 11,608
  • 7
  • 52
  • 62
  • Thank you Ergec. I am getting closer. Now I see the letters AF instead of ?? Curious how to display that as emoji though. – spreaderman Jan 12 '22 at 04:12
  • 1
    That is because not all browsers support country flag emojis. Only Firefox. Try a smiley face, you'll see it will work on all browsers. – Ergec Jan 12 '22 at 07:14
  • 1
    Thank you and all well understood now. Thank you to all for helping me understand this. – spreaderman Jan 12 '22 at 07:49