0

In a PHP script that should perform some tasks (no output except for logging messages) I extract data from MySQL DB. I noticed that echoing some data has black diamond question mark like Componenti Elettronici�. Seems that everything is in UTF-8 and I don't know where that diamond comes from (no trace in DB field, apparently) and, most important, how to remove/replace

On top of PHP script I have:

ini_set('default_charset', 'utf-8');
header("Content-Type: application/json");

DB table collation is utf8mb4_general_ci. Database connection is also utf8mb4

What I tried so far:

  • echo strlen($str); outputs 23, that is the real 22 chars of Componenti Elettronici + black diamond
  • echo mb_detect_encoding($str, mb_list_encodings(), true); outputs UTF-8
  • echo iconv(mb_detect_encoding($str, mb_list_encodings(), true), "UTF-8", $str); does not change output: the black diamond is still there, of course because I'm converting from UTF-8 to UTF-8, thus doing absolutely nothing

That black diamond prevents me from indexing data in an Elasticsearch environment, that's the big problem

So, why I have that black diamond? How can I remove or replace it? Thanks in advance

Ivan
  • 2,463
  • 6
  • 39
  • 51

0 Answers0