jmadler / emoji-picker

Add a slick emoji selector to input fields and textareas on your website.
Other
1.32k stars 318 forks source link

How to save Emojis to MySQL #135

Open tiomanisland opened 5 years ago

tiomanisland commented 5 years ago

Demo works fine but on Submit form (to .php) I am not getting tags like :heart: or :cars: but UTF emojis. I would like to use images (not UTF characters) and I don't know how to intercept form field with emoji-tags, save them and later display that post with images.

The demo simply replaces graphics emojis with UTF which is not what I need.

I want text box to return me:

Hello this is :heart: and it looks lovely --> (form submit) --> php then I would save this to DB later I would read from db and replace :heart: with correct emoji image

Can someone help?

tiomanisland commented 5 years ago

:heart: should be : heart : but github replaced it with icon

atakane commented 5 years ago

Set your input field to accept Unicode by adding data-emoji-input="unicode" and set your MySQL fields as UTF-8 or UTF-16. Once you have done it, you could easily store the emojis and read them back as Unicode.

antoiba86 commented 5 years ago

There are several ways to accomplish this.

Instead of send your input value, you can send the value of the input that is converted in the nuew input that has the class "emoji-wysiwyg-editor". With this way, the editor will have the emojis converted as images.

Another way is getting the alt of the imgs of the emojis. For example, this will have the emoji : hearth : and you can saved it in database. Later, you can convert them with a function from the emoji picker packages. I used the classes inside to create a function to solve this problem.

umnibot commented 4 years ago

To save the emojis into the db set the collation of the field to "utf8mb4_general_ci"

And to read them after a MySQL select, use

mysqli_set_charset($connection, 'utf8mb4');

right after the mysqli_connect (or whatever type of connection you are using).

Hope this helps someone

dominicklee commented 4 years ago

To convert the unicode versions back into the same images you see in the Picker, you can do:

window.emojiPicker.appendUnicodeAsImageToElement($("#yourDivID"),"😃")

Replace yourDivID with whatever the id of your element. You can also use getElementByID('yourDivID') instead.

JSGund commented 4 years ago

I want to get Unicode from input or textarea? but getting as "Hello 😃", so I can store the Unicode in the database and get it to convert to image using EmojiPicker methods.

jlwegaba commented 2 years ago

Am using ci4. At first i was getting ???? for the emojis in DB. Changed in App-> Config -> Databases.php my DB settings to following and all worked well. Could see the emojis in DB.

'charset' => 'utf8mb4', 'DBCollat' => 'utf8mb4_bin',