I built a PHP web page and some of the characters are like this
⇾ ....
â€....
etc
Please help me on how to eliminate this
If you're not using UTF-8 characterset, I would try to change the encoding of the database to avoid these characters:
How to convert an entire MySQL database characterset and collation to UTF-8?
Related
I am working with a large number of foreign characters in SQL and I cannot seem to get them to save correctly;
Júlio César
Luisão
What is the best way to deal with special characters in mysql is it a setting in the data formats or do you format the data in php before you add it to the database?
Thanks
You need to set the encoding of your database (and tables) to utf8, set the connection encoding to utf8, and use utf8 as the encoding of the php files themselves.
That looks like "double encoding". It is discussed in
http://mysql.rjweb.org/doc.php/charcoll
I used this webpage http://javascriptobfuscator.com/default.aspx to obfuscate a small script.
$(document).ready(function(){
$("#likee").fadeOut("fast");
});
And the obfuscated code is:
$(document)["\x72\x65\x61\x64\x79"](function (){$("\x23\x6C\x69\x6B\x65\x65")["\x66\x61\x64\x65\x4F\x75\x74"]("\x66\x61\x73\x74");} );
I am using a form to insert the obfuscated code into mysql. However, when I inserted the code I got this:
$(document)["x72x65x61x64x79"](function (){$("x23x6Cx69x6Bx65x65")["x66x61x64x65x4Fx75x74"]("x66x61x73x74");} );
Does anybody know why backslashes are removed?
Will my code work without backslashes?
I believe it has something to do with the encoding. I guess that you are using the utf8 encoding format for the text/varchar (or some sort) column where the data is inserted in.
The utf8 encoding format only accepts unicode characters that can be represented with 3 bytes, but the \x23 character needs 4 bytes, so mysql strips the character.
How to solve?
Do you have mysql 5.5 or later? You can change the column encoding from utf8 to utf8mb4. This encoding allows characters of 4 bytes.
Source: "Incorrect string value" when trying to insert UTF-8 into MySQL via JDBC?
I have been using php + mysql (phpmyadmin) to construct websites with Chinese contents (utf-8) for a long time.
When inputting forms, and also generate output php from db, the Chinese Words display well; but when I look at the database, although sometimes they are normal chinese characters, but something they are not (become strange strings), that made me notice that, the way that mysql handle and input data is not always utf-8.
Some experts on web mentioned, mysql were used to record the input data by latin1; nevertheless, I note that the existing charset in phpmyadmin is utf-8...
Will there be any solid way to detect the encoding format of chinese characters appeared in a phpmyadmin table cell?
Also, apart from mentioning at header of the page, will there be any method so that I can make sure the data entered to the db is utf-8 but not others?
Thank you.
The biggest problem that people encounter in this regard is that they don't tell MySQL that they're sending/expecting UTF-8 encoded data when connecting to the database, so MySQL thinks it's supposed to handle latin1 encoded data and converts it accordingly. Issue the command SET NAMES utf8 after connecting to the db or use mysql_set_charset.
in my case, it just because htmlentities(); Solution is change echo htmlentities($email_db); to echo htmlentities($email_db, ENT_COMPAT, 'UTF-8');
I am facing a paradox in decoding with utf8_encode decode. I have a MySQL database with uft8 collation and whose fields have the utf8_general coding. I have my php file in utf8, and in my HTML pages I have specified in the header the utf8 charset.
My problem is that when I select from my table a field containing accented characters (like èçò ùé) and echo that to the browser, I get strange characters.
To resolve my problem, I have to echo $description=utf8_encode($imm['description']).
My question is why can’t I do the echo directly without having to use uft8_encode every time?
I'll just guess that your database connection is not set to UTF-8.
See SET NAMES utf8 in MySQL?
you need to specify the header using php to be utf-8. also make sure that the format of the chars is utf-8 before storing in the db because utf_encode encodes an ISO-8859-1 string to UTF-8, which most likely means that the chars are being stored as ISO-8859-1 in s a utf-8 table.
make sure that you convert those chars in utf-8 before storing them in the db and then echo should not be a problem at all.
Source: had the exact same problem myself.
What is the best Collation for the column that can allow to store accented letters and parse them out perfectly without any encoding error, because whenever I add an accented letter such as é, å, it shows out with an encoding problem on the PHP side, but in the MySQL side it's fine...
How do I get the accented letters display properly?
You get them correctly by matching the encoding on both ends, ie. both your PHP output and your DB should use the same encoding. For European languages I would suggest using UTF-8 for both your scripts and the DB. Just remember that you still have to initialize UTF-8 collation in MySQL using SET NAMES 'utf8' COLLATE 'utf8_general_ci' (so run this query just after you make a connection to the DB and you should be ok).
Perhaps your problem isn't within the database, but within however you're displaying things from PHP? What content encoding are you specifying in your output? You might need to manually send a header to specify that the content is UTF-8 if that's what you're trying to output.
For instance: header("Content-Type: text/html; charset=UTF-8");