How can I store emoji from TextMesh pro in a database using the WWW class to post the string containing the emoji as a parameter in the URL?
I'm having a problem getting the emoji from a TextMesh Pro text field into my database. When I try, the emoji data is stored in plain text like this: 😂 or like this � or like this □ depending on which encoding i try.
I have a php script that uses a sql statement to store the text in my mysql database. And when I manually type the url of the php script in my browser and add the emoji as a parameter it works perfectly fine, it properly stores the emoji (as I have already set the collation of my database to utf8mb4).
Here's the part I don't understand: if I take the string that contains the emoji through my c# code and access the php file with the string as a parameter, it doesn't work. It stores the emojis as mojibake. (😂 this sequence of characters should be this: ).
It stores the text just fine otherwise, so there's no problem with the code below. Here's how it looks:
public IEnumerator UpdateChatCR(string gameID, string text)
{
string hash = Md5Sum(gameID + secretKey);
print("posting to chat db: " + text);
string post_url = updateChatURL + "&game_id=" + gameID + "&text=" + text + "&hash=" + hash;
WWW www = new WWW("http://" + post_url);
yield return www;
if (www.error != null)
{
print("There was an error updating the chat in the DB: " + www.error);
}
else
{
//print(www.text);
}
}
I have tried different ways of encoding the text, but to be honest I have no idea what I'm doing at this point. I tried different variations of the following code, but with no luck:
byte[] bytes = Encoding.UTF8.GetBytes(tmpField.text);
string encodedText = Encoding.Default.GetString(bytes);
I've been searching for an answer for the last few days. And I've come to the point where I realize I probably have to read a book about encoding and emoji unless there's someone out there who can help me out...
Thank you for your time.