store and display emoji Android+PHP+MySql [duplicate] - php

This question already has an answer here:
Storing and showing emojis in Android application using MySQL
(1 answer)
Closed 5 years ago.
In my android app, from the textview i am reading the text with emoji from the user as --
String textmsgGet = mTextView.getText().toString().trim();
String textmsg = StringEscapeUtils.escapeJava(textmsgGet);
And display it in another activity as --
String titleGet = jsonObject.getString("title");
String title = StringEscapeUtils.unescapeJava(titleGet);
In my php page, while reading the value, i am using --
$textmsg = $_POST['textmsg'];
And while display, i am using 0--
$title = utf8_encode($data['textmsg']);
but in my database, the values are stored as --
\u1F601 hello \u1F601
what the thing i am missing, any help will be great. thnx

Try converting your entire mysql database and tables character-set and collation to UTF-8 like this:
ALTER DATABASE databasename CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE tablename CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
And instead encoding the text whe you want to display, try decoding it:
$title = utf8_decode($data['textmsg']);

Related

decode encoded value in php mysql [duplicate]

This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 4 years ago.
राम (hindi language)
I am working on a table where many rows contains value like this राम it shows in browser like राम and many rows already contains राम but
I want to replace all encoded value with decode values for this i used find replace query also put data in form and updated but every time db stores encoded value
Structure of table
hindi varchar(256) utf8_unicode_ci
what i did
<?php
echo $queryfetch="select hindi from users where id='2'";
$resultfetch=mysqli_query($c,$queryfetch);
while($row = mysqli_fetch_array($resultfetch))
{
echo $queryupdate="update users set hindi='".html_entity_decode($row['hindi'])."' where id='2'";
$resultupdate=mysqli_query($c,$queryupdate);
}
?>
select hindi from users where id='2'
update users set hindi='राम' where id='2'
**
sql before =राम
**sql after = राम**
What you have are html-encoded characters. To decode them, you need:
html_entity_decode('राम')
An example.

Emoji character (😀) is not working with utf8mb4_bin in MySQL version 5.6 [duplicate]

This question already has answers here:
iPhone emoticons insert into MySQL but become blank value
(2 answers)
Trouble with UTF-8 characters; what I see is not what I stored
(5 answers)
Closed 5 years ago.
I am trying to save emoji symbol to database record but each time it's not saving properly.
I've referred this How to store Emoji Character in My SQL Database but still not working.
As per solution on above question, I tried to change the character set from utf8 to utf8mb4 and collation from utf8mb4_bin.
I tried everything like resetting to default and then changing it in the database table. I tried utf8mb4_unicode_ci, utf8_unicode_ci and utf8mb4_bin but it's not working.
I am using MySQL 5.6 version. And I am changing the collation with below query
alter table `users` convert to character set utf8mb4 collate utf8mb4_bin;
The above code is working fine, it's changing the UTF type in database. But emoji is not saving properly it's saving as question marks (????)
Below is my database table structure example:
CREATE TABLE IF NOT EXISTS `users` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'System generated id used for uniqueness',
`introduction` longtext COLLATE utf8mb4_bin,
`other_details` longtext COLLATE utf8mb4_bin,
PRIMARY KEY (`id`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=41213 ;
To save emoji using below PHP code:
$dom = new DOMDocument('1.0', 'UTF-8');
$strWithEmoji = "😀";
$fullContent = '<meta http-equiv="content-type" content="text/html; charset=utf-8">'
+ $strWithEmoji;
$this->save($fullContent); // Function for saving into database
I don't know exact how many bytes are storing but I am trying to save only
this emoji character "😀" and it's storing it as 4 question marks (????).
I tried all solutions from below links, but didn't worked for me:
How to store Emoji Character in My SQL Database
UTF-8 all the way through
The ultimate emoji encoding scheme
The connection needs to specify utf8mb4 to MySQL. What is under the covers in DOMDocument?
😀 is hex F09F9880, which should work in a column of CHARACTER SET utf8mb4 with any utf8mb4_* collation.
And here is another link: Trouble with UTF-8 characters; what I see is not what I stored
If all else fails, execute SET NAMES utf8mb4 from PHP after establishing a connection.

PHP form doesn´t save the accent marks into MySQL DB [duplicate]

This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 5 years ago.
I store info into a MySQL Database via a PHP Form, the problem is that is a person inputs into the name field José Molína in the database it saves JOSé MOLíNA so it convert the accent mark into a non legible name and when I displys the info of the database in a form it shows Jos Molna (doesn´t show the letters with the accent marks).
the info of my table is ENGINE=MyISAM DEFAULT CHARSET=latin1 and the forms captures the info from a Wordpress site, could you please tell me what is the problem?
this is the way I sent the info to the database
$strNombres = htmlspecialchars(rtrim($_POST['nNombres']));
$Nombres= filter_var($strNombres, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH);
the I tried with this one but no solution
$strNombres = strtoupper((rtrim($_POST['nNombres'])));
$Nombres = htmlentities($strNombres, ENT_QUOTES,'UTF-8');
to the manager:
since you closed this question, can you tell me where is the duplicate sign where the question was edited? besides of that I would like to close my account, how come you close a question?
I just send a message via twitter for this.
You need to change the charset of your table
ALTER TABLE tbl_name CONVERT TO CHARACTER SET charset_name;
In your case you should replace tbl_name with your table name
ALTER TABLE tbl_name CONVERT TO CHARACTER SET 'UTF-8';

Storing and showing emojis in Android application using MySQL

I have an application talking to a NodeJS server via socket, that server is talking to PHP via HTTP, and that PHP is using MySQL.
When I try to insert Emojis in a text field, and save it to DB, when I get it back I see "?".
If I copy Emojis from wikipedia (for example ✒️ ❤️ 🀄️ 🈚️) and force them to the DB, when I select them it shows ✒️ ❤️ ?️ ?️
Note: The field in DB is utf8mb4bin.
Why can't I store emojis directly from my device to DB?
Why does some emojis show, while others don't?
Note: I also tried only PHP and MySQL, but with no luck.
1.)Database :
Change Database default collection as **utf8mb4 ** .
2)Table :
Change Table collection as ** CHARACTER SET utf8mb4 COLLATE utf8mb4_bin **.
Query :
ALTER TABLE Tablename CONVERT TO CHARACTER SET utf8mb4 COLLATE
utf8mb4_bin
3)Code :
insert into tablename (column1,column2,column3,column4,column5,column6,column7) values ('273','3','Hdhdhdh😜😀😊😃hzhzhzzhjzj 我爱你 ❌',49,1,'2016-09-13 08:02:29','2016-09-13 08:02:29')
4)Set utf8mb4 in database connection :
$database_connection = new mysqli($server, $user,$password,$database_name);
$database_connection->set_charset("utf8mb4");

Wrong charset in mysql [duplicate]

This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 8 years ago.
I have a page with forms to add or edit a entry to a mysql-database. Everything works fine, the form shows everything right, the output on the page is right.
Only when I open the mysql-database (phpMyAdmin) the entries are shown wrong. Some german letters are wrong.
For example André instead of André. Or groß instead of groß.
The Output on the page works fine. Also the edit-function in an HTML-form works fine.
I just don't understand why everything is written wrong in the database.
All my PHP-Page are in "utf-8".
Access this link:
http://dev.mysql.com/doc/refman/5.0/en/charset-applications.html
When you create a database, you can set CHARACTER SET by utf8.
Example:
CREATE DATABASE tablename
DEFAULT CHARACTER SET utf8
DEFAULT COLLATE utf8_general_ci;
Make sure your database has UTF8 char set as well
You can convert you existing table like this:
ALTER TABLE tablename CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Add Header to the top of your php code. This will set encoding of content.
header('Content-Type: text/html; charset=utf-8');
You can use any encoding, which is set in your database instead ofutf-8.

Categories