Sorry guys, it's been a very long time since I wrote anything, as I was suffering from fever, LoL. 🤣

The title of the post is really deceiving I agree. It is not about my CV or “Résumé” really. 😳 Rather, it is about the recent adventure I went through, when I was working with our very own PHP & MySQL data. Well, this is what happened. I had stored some Unicode Content (UTF-8) into the Database 🛢️ (the real use-case here was German and French names) and when they were echoed in PHP, they were looking like:

The code behind was rather simple. 🤦🏻‍♂️

<?php  
  $result = mysqli_query($conn, "SELECT `Content` FROM `Table` WHERE `ContentID` = 1");
  $data = mysqli_fetch_assoc($result);
  echo $data["Content"];
?>

The interesting part was, when I was just using this code, I was getting the right one this way:

But, the moment I used the <!DOCTYPE html> and other semantic tags, it went back to being:

I couldn't find out the real reason behind why it was behaving this way. 🤔 But I did try these things:

  1. Set the MySQL Content Encoding as UTF8-MB4 General.
  2. Programatically set the above using mysqli_set_charset($link, 'utf8mb4');.
  3. Gave a <meta /> tag that instructs the browser that the content is in charset="utf-8".
  4. Tried server side variant of the above using header('Content-Type: text/html; charset=utf-8');.
  5. Tried variants of htmlspecialchars, htmlentities, etc. without any luck.

But nothing worked. 👎🏻 Finally, I was checking what would be the right way of displaying and found out another nice example in PHP. It is none other than mb_convert_encoding, which saved my life. So while echoing out stuff, I called them this way:

echo mb_convert_encoding($data["Content"], 'UTF-8', 'ISO-8859-1');  

Even though it was slightly longer than the traditional echo, this saved my back today. 😁 Do you have any similar stories? Please pen them down in the comments section! 💬