 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
 |
|
 |
06-19-2009, 04:07 PM
|
#1 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
Weird UTF-8 problem
Hey!
I've hit a weird error.
åäö gets all weird signs(like squares with a ? in it), but all the charset is set to utf-8 so it should work.
All the files are encoded as utf-8 without BOM.
It worked great(without the weird signs) before I added some stuff to the database, and now those gets weird signs in it.
I checked my database, and it's the way it's supposed to be.. columns are swedish_latin_ci or w.e it's called.. :S
Anyone have an idea?
__________________
|
|
|
|
06-19-2009, 04:33 PM
|
#2 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
Try setting your database collation to utf8_general_ci, and that the output in the browser is UTF-8 by viewing the page information.
You can also try running the following query:
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|
06-19-2009, 05:10 PM
|
#3 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
|
You can also skip setting a language preset in the database it works as well :)
EDIT:
also you can run:
html_entities on it, that works & nl2br
OR
Set,
ISO Latin 1
AND:
set this,
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Last edited by codefreek : 06-19-2009 at 05:26 PM.
Reason: more info..
|
|
|
|
06-19-2009, 05:17 PM
|
#4 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
I ran that query.
I set all the columns to utf8_general_ci.
I set the table to utf8_general_ci.
And the database was already utf8_general_ci.
None of it worked..
Could it be something in the connection on the PHP side?
'Cause all the rest of the text that is staticly printed on the page is working perfectly.
__________________
|
|
|
|
06-19-2009, 05:23 PM
|
#5 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
Is the data being output to the browser in UTF-8?
Note Encoding.
http://www.grabup.com/uploads/600019...1809237F10.png
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|
06-19-2009, 05:24 PM
|
#6 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
|
Read my post..
|
|
|
|
06-19-2009, 07:42 PM
|
#7 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
@codefreek- Charset on the html page is already utf8, and "SET Latin1"... would only bring it back to how it was in the beginning because that's what it was at first. html_entities wouldn't work, and nl2br shouldn't work either as it only converts nls(\n - ENTER) to <br />.
@wildhoney-
It looks like this:
http://img34.imageshack.us/img34/7146/utferror.jpg
Btw, as you see.. the staticly printed "Användarpanelen" at top right is output correctly, so there's nothing wrong with the file-encoding. There must be something with the database since it's only the data from the database that are being shown with those errors..
__________________
|
|
|
|
06-19-2009, 11:01 PM
|
#8 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
A simple test and it appears to work for me, even with the page encoding as ISO-8859-1.
That code on a blank canvas with the table as so: http://www.grabup.com/uploads/430020...0009007F40.png
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|
06-20-2009, 01:19 AM
|
#9 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
|
Tanax, well hum i did all those thing's before and it worked for me but you might wanna google on it :)
|
|
|
|
06-20-2009, 02:51 AM
|
#11 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
I use SQLYog 
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|
|
The Following User Says Thank You to Wildhoney For This Useful Post:
|
|
06-20-2009, 01:10 PM
|
#12 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
Argh, so how come it doesn't work for me 
It should work!!
__________________
|
|
|
|
06-20-2009, 07:05 PM
|
#13 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
You could try sending the correct HTTP header (if your not already :) )
PHP Code:
header('Content-type: text/html; charset=UTF-8');
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
|
|
|
|
06-21-2009, 12:06 AM
|
#14 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
Well, by looking at the pageinfo and the charset of the output on the page, it's set to UTF-8 already..
Could this be something due to I'm using a MVC-framework? I remember I had some troubles with this while using CodeIgniter..
I'm using my own MVC-framework right now, but could probably be the same issue here. Though I have no idea how to solve it since I don't have the options that I changed in order to make CI work correctly..
Could that be the problem anyways?
__________________
|
|
|
|
06-21-2009, 03:09 AM
|
#15 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
|
tanax, can be but, should not be the problem..
|
|
|
|
06-22-2009, 10:36 AM
|
#16 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
you could try converting the contents of your DB to utf with iconv.
NOTE:
the text 'sketch@talkphp:~$' is my attempt at emulating the command line
Code:
sketch@talkphp:~$ mysqldump -u user -p databasename > databasename.sql
You may want to create a backup DB:
Code:
sketch@talkphp:~$ mysql -u username -p
mysql>create database databasename-backup;
mysql>exit
Bye
sketch@talkphp:~$ mysql -u username -p databasename-backup < databasename.sql
Now we can run the dump through iconv
Code:
sketch@talkphp:~$ iconv -f Latin1 -t utf8 databasename.sql > databasename-iconv.sql
Now create a new DB or reuse the old on and dump it back in (making sure that the tables and database are set to utf8):
Code:
sketch@talkphp:~$ mysql -u root -p databasename < databasename-iconv.sql
Sorry, i don't know how you would do this on redmond.
Alternitively you could try this fudge.
basically convert the column with the problem data in to a binary format then convert back the charset to utf8 again, this should force mysql to convert the data.
Code:
sketch@talkphp:~$ mysql -u root -p databasename
mysql>alter table tbl_name modify column col_name CHAR(255) CHARACTER SET binary;
mysql> alter table tbl_name modify column col_name CHAR(255) CHARACTER SET utf8;
obviously replace the 'CHAR(255)' with whatever the current data type is.
I haven't tested it, so you would be best advised to create a backup!
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
|
|
|
|
06-22-2009, 08:48 PM
|
#17 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
Wow, that is waay too complexed for me 
Damnit. I've had åäö working with databases before :S
It must be because of my framework.. 
__________________
|
|
|
|
06-23-2009, 09:36 AM
|
#18 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
|
Tanax: try without your framework ?
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|