TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-19-2009, 04:07 PM   #1 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default 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?
__________________
Tanax is offline  
Reply With Quote
Old 06-19-2009, 04:33 PM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

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:

sql Code:
SET NAMES 'utf8'
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 06-19-2009, 05:10 PM   #3 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

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..
codefreek is offline  
Reply With Quote
Old 06-19-2009, 05:17 PM   #4 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

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.
__________________
Tanax is offline  
Reply With Quote
Old 06-19-2009, 05:23 PM   #5 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

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.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 06-19-2009, 05:24 PM   #6 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

Read my post..
codefreek is offline  
Reply With Quote
Old 06-19-2009, 07:42 PM   #7 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

@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..
__________________
Tanax is offline  
Reply With Quote
Old 06-19-2009, 11:01 PM   #8 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

A simple test and it appears to work for me, even with the page encoding as ISO-8859-1.

php Code:
$szSQL = "SELECT * FROM swedish";
$pResultSet = mysql_query($szSQL);
$pResult = mysql_fetch_row($pResultSet);

echo $pResult[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.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 06-20-2009, 01:19 AM   #9 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

Tanax, well hum i did all those thing's before and it worked for me but you might wanna google on it :)
codefreek is offline  
Reply With Quote
Old 06-20-2009, 01:40 AM   #10 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

Wildhoney, what Database editor are you using, in this pic..
http://www.grabup.com/uploads/430020...0009007F40.png
codefreek is offline  
Reply With Quote
Old 06-20-2009, 02:51 AM   #11 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

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.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
The Following User Says Thank You to Wildhoney For This Useful Post:
codefreek (06-20-2009)
Old 06-20-2009, 01:10 PM   #12 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Argh, so how come it doesn't work for me
It should work!!
__________________
Tanax is offline  
Reply With Quote
Old 06-20-2009, 07:05 PM   #13 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

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)
sketchMedia is offline  
Reply With Quote
Old 06-21-2009, 12:06 AM   #14 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

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?
__________________
Tanax is offline  
Reply With Quote
Old 06-21-2009, 03:09 AM   #15 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

tanax, can be but, should not be the problem..
codefreek is offline  
Reply With Quote
Old 06-22-2009, 10:36 AM   #16 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

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)
sketchMedia is offline  
Reply With Quote
Old 06-22-2009, 08:48 PM   #17 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Wow, that is waay too complexed for me
Damnit. I've had åäö working with databases before :S

It must be because of my framework..
__________________
Tanax is offline  
Reply With Quote
Old 06-23-2009, 09:36 AM   #18 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

Tanax: try without your framework ?
codefreek is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Huge Session Problem Killswitch General 1 11-17-2008 02:36 AM
Strange string comparison problem Jelmer General 0 05-23-2008 04:00 PM
A bug or a cache problem?! yazid Advanced PHP Programming 0 05-22-2008 08:40 AM
ÅÄÖ (charset=iso-8859-1) problem cthemaaan Advanced PHP Programming 6 03-28-2008 11:08 AM


All times are GMT. The time now is 06:27 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design