0

I have a self made text-editor, with a feature whereby you can insert unicode characters onto a (editable) div. For example a speaker-icon is represented by the following string:

🔊

and after inserting this string as a textnode it will directly be rendered correctly within the div as

🔊

When I export the content of my editor I basically submit the div.innerHTML and store in the mysql database.

I however want the innerHTML to preserve/keep the hex representation of the character instead of the rendered version, for example an output string like

this is a <span style='color:green'>speaker-icon: &#x1f50a;</span> in my message.

The reason is that in mysql the icon is else stored as '???' . Mysql uses utf8mb4_general_ci as collation. Also I want to keep the HTML as portable as possible regardless of collation.

Is this possible?

PS I am using PHP as back-end.

Patrick
  • 383
  • 1
  • 2
  • 19
  • Storing it correctly in MySQL is an eminently solvable problem: https://stackoverflow.com/a/34637891/476. I'd also argue that proper UTF-8 is a lot more portable than HTML entities, which are only relevant in an HTML context. – deceze Jun 28 '18 at 08:44

1 Answers1

0

Probably the connection did not specify utf8mb4 in the connection and/or the column definition.

See "question mark" in Trouble with UTF-8 characters; what I see is not what I stored

Rick James
  • 135,179
  • 13
  • 127
  • 222