All, Im having the age old problem with character encoding...
I have a mySQL DB with a field set to utf8_unicode_ci. My PHP page as the header entry <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />. When I use a simple form to POST data with Cyrillic characters to the DB, e.g. 'гыдлпоо', the characters display correctly in the textarea, and are added to the DB where they display correctly.
When fetching the characters from the DB, my page only displays a series of question marks. I've used mb_detect_encoding($content, "UTF-8,ISO-8859-1", true); and the content is UTF-8, however the characters do not display.
I've searched around (including on SO) and tried any number of solutions, to no avail- any help would be much appreciated.
Many thanks
Do this right after mysql_connect() and mysql_select_db():
mysql_query("SET NAMES 'utf8'");
Try using mysql_set_charset() function before fetching data from database.
did you try to use the form with
enctype="multipart/form-data"
?
this might help.. it's not necessary for the text to be readable in your database.. when they are saved they should be utf8 encoded.. you need them to look fine when you output the string again
Related
So when I retrieve a column from my database and echo the string in php it displays microsoft special chars as this �.
However if I copy the string from the cell, paste it into my script and echo it directly, I get the correct content.
At what stage between retrieving the data and displaying it is this going wrong?
It is an MS SQL database. If any more information on current set up will help, let me know and I will supply it, it's just at this point I'm not sure what will be usefull and what wont.
It's down to encoding.
Is your database table encoded in the same character set as the PHP document, e.g. UTF=8?
If you can, either change the database table's collation or the PHP document's encoding, either with
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
or
header('Content-Type: text/html; charset=utf-8');
with the correct character set.
Information that I send to mysql with accents are appearing with strange chars, for example správce is admin in my language. And when I send this to mysql it appears like "správce".
Im trying to find information to solve this problem, and I saw two solutions, but any is working.
1st solution with meta tags, dont works:
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
2º solution with htmlspecialchars method also dont works
if($f['level_admin'] == '1') { $f['level_admin'] = htmlspecialchars('Správce', ENT_QUOTES, "UTF-8"); }
if($f['level_admin'] == '2') { $f['level_admin'] = htmlspecialchars('Super Správce', ENT_QUOTES, "UTF-8");}
Do you know some way that work effectively?
It's also important to know what collation is set in the MySQL DB Table - dependent on your needs you could use for example "utf8_unicode_ci" .
There is also a php function that converts string to UTF8
utf8_decode()
utf8_encode()
Normally this helps - but you better check the collation in the DB.
I got a varbinary field in my database, and got some problems with displaying special (Polish) characters like ąśćężźć.
Example: SELECT local_name from items WHERE id = 140 returns: Pieczęć, the problem appears when I want to print this data on my website (encoding UTF-8 there), then the Pieczęć turns into the following string: Piecz�� tried also to use utf8_encode() PHP function but it gives the following result: Pieczêæ.
How can I solve that so it will print the special characters without problem?
same adivce as here:
https://stackoverflow.com/a/11254131/1489924
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
and/or
SET NAMES 'utf8'
worked for me in most situations.
Good luck!
I've got the following problem with my PMA-GUI:
While the data submitted by PHP-Scripts to my database is displayed correctly, ONLY PMA displays several german Umlaut's (such as äüß, ..) as ü or ä
The problem occurs also while exporting tables to file..
MySQL: 5.0.51a-3ubuntu5.8
PMA: 3.4.5
Database & fields are utf8_general_ci
Does anybody know a solution?
Are you sure that your client is sending data as utf-8?
this seems to me a duplicate of:
German Umlaute in Mysql/Phpmyadmin
You need to ensure you use consistent use of character set/character encoding.
For example, to normalise to UTF-8 content, your DB fields' character sets should be set to UTF-8. Then, in your PHP (if you have your own scripts running that fetch DB information) you need to then add to the head section:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Then, in the PHP, before any output to the browser, include the content type PHP header:
header ('Content-type: text/html; charset=utf-8');
Before you run any SQL to fetch content (so after you connect, but before executing your query), use mysql_set_charset:
mysql_set_charset('utf8',$link);
// $link is optional, refers to your DB connection
You can think of it as three steps:
The step used to add the characters to your DB
Storage of characters in your DB
Retrieval and display of characters
The simplest bet to ensure conformity and that characters display as you anticipate, is to ensure the correct, consistant, character set is defined at each stage.
I am populating this mysql table with data from a php (via post and using filter_input).
The database is utf8 but when I have a user that inputs words with ^,',',~ like Não I get this -> Não
What do I have to do to make it show the correct values. Or should I try to make some correction when I retrieve the data??
UPDATE:
I have added a utf8_decode and now it is inserting ok.
Anyone know how to convert the string that were already in the table?? I tried using the convert function but I can't make it work :(
UPDATE:
I am trying this code:
select convert(field using latin1)
from table where id = 35;
And I am still getting this: Não
I tried other encoding s but I never get the word Não
Anyone have any thoughts on this one??
First, make sure your page is utf-8
<meta http-equiv="Content-type" content="text/html; charset=UTF-8"/>
next, if your on Apache, make sur your in UTF-8 in config file :
AddDefaultCharset UTF-8
or your can do it in a .php file like this :
header('Content-type: text/html; charset=UTF-8');
if you still have problem, you can use the encode function :
$value = utf8_encode($value);
Hope all this will help...
It looks like somewhere along the way something cannot handle Unicode. As a result, ã is getting interpreted as two separate characters. Make sure everything that handles strings is OK with Unicode.