Q:

make emoji view-able in the message-box

Screenshot of issue
I am creating a messaging application and want to make emoji images viewable rather than showing their codes in the messages.
I have used an emoji picker js file for entering them in the text area but in sent messages the emoji icon is not showing.
I use the following function :
function loadMessages($token){
    // this function is loads all the messages from the database
    $db = connect(); 
    $me = $_SESSION['id']; 

    $query = $db->prepare("SELECT * FROM messages WHERE (fromm=:fromm1 AND too=:too1) OR (fromm=:too2 AND too=:fromm2) ");
    $query->bindParam(':fromm1',$me);
    $query->bindParam(':too1',$token); 
    $query->bindParam(':too2',$token); 
    $query->bindParam(':fromm2',$me); 
    $query->execute(); 
    $found = $query->rowCount(); 

    if($found){
        while($row = $query->fetch(PDO::FETCH_ASSOC)){

            $from = $row['fromm'];
            $to = $row['fromm']; 
            $message = $row['message'];

            $text = $row['message'];
            $html = preg_replace("/\\\\u([0-9A-F]{2,5})/i", "&#x$1;", $message);

            if($from == $me){
                $realMessage = "<div class='me'> $html <br /><br /></div>"; 
            } else {
                $realMessage = "<div><div class='you'>$html<br /><br /></div></div>"; 
            }

            echo $realMessage;

        }

The main index.php includes this: 
<div class="display-message" style="position: absolute; width: 100%; padding: 10px; background: inherit; bottom: 0;"> 
                    </div>

A:

Hi and welcome to Stack Overflow.
There is an encoding issue. You are seeing the Latin output of the characters rather than Unicode (is your database encoding set to something other than UTF-8?).
Get PHP to output the following header before any other output:
header('Content-type: text/html; charset=utf-8');

Add the following meta tag in your <head> section:
<meta charset="utf-8">

And in your loop:
...
    while($row=$query->fetch(PDO::FETCH_ASSOC)){
        $from=$row['fromm'];
        $to=$row['fromm']; 

        $message=preg_replace("/\\\u([0-9A-F]{2,5})/i","&#x$1;",$row['message']);
        $message=mb_convert_encoding($message,'UTF-16','HTML-ENTITIES');
        $html=mb_convert_encoding($message,'UTF-8','UTF-16');
    ...

