decode encoded value in php mysql [duplicate] - php

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.

Related

How to update with concat and if statement? [duplicate]

This question already has answers here:
Is storing a delimited list in a database column really that bad?
(10 answers)
Closed 3 years ago.
I have a table with contact codes. When contact code is not specified there are ^^ in the empty cell. If specified should be: ^Code123^,^Code321^,^Code987^
I want to update this cell, but I dont know how to rewrite empty cell with ^^?
With my query I get this result ^^,^Code123^,^Code321^,^Code987^. How to delete ^^ when updating cell?
$sql6 = "UPDATE contacts
SET clicks_c=IF(clicks_c='',
'^".$url_name."^',
CONCAT_WS(',',clicks_c,'^".$url_name."^'))
WHERE id_c='".$row_id."'";
If an empty cell contains ^^, you need to test for that in your IF(). Change:
IF(clicks_c='',
to:
IF(clicks_c IN ('', '^^),
Then it will replace ^^ with a nonempty code, instead of concatenating to it.

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

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']);

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';

MySQL russian text error [duplicate]

This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 9 years ago.
I have a problem with inserting proper data into my DB with php...
I am trying insert some data with this code:
$query1 = "insert into `exercises`(`exercise_name`) values ('".$txtEName."');";
$query2 = "insert into `exercises_type`(`type_name`) values ('".$txtEType."');";
mysqli_query($connnect, $query1);
mysqli_query($connnect, $query2);
all data is russian text... all data is saving into the DB, but, in DB it looks like
so what I am doing wrong?
You can check for correct charset/collation. As this may help you to insert correct data in you table. also you can use character encoding for values your are getting by $_POST.
This link may help you

UTF-8 characters not inserted as UTF-8 into MySQL table from PHP [duplicate]

This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 9 years ago.
I am trying to insert records containing Hebrew characters from PHP into a MySQL table.
Both the schema and the table are set with utf8 character set in MySQL.
The Web-site is set with a charset=UTF8.
Displaying the query on the web-page renders Hebrew correctly.
However, once inserted into the MySQL table, the Hebrew characters are not stored correctly, rather as gibrish. Example:
×בו סנ×ן
Tried to apply utf8_encode and mb_convert_encoding on the query string - to no avail.
What am I missing?
Thanks!
Maybe try:
$q = mysql_set_charset('utf8');
var_dump($q);
The var_dump should tell you if the string has been encoded properly before insertion into the database. If it is, the problem lies in the database, if not, the problem lies elsewhere.
if you use mysqli try this set_charset("utf8"); directly after new mysqli()
Example:
$db = new mysqli($config['database']['host'], $config['database']['user'], $config['database']['password'], $config['database']['dbname']);
$db->set_charset("utf8");

Categories