é = é

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

é = é

Post by GeXus »

I'm grabbing some data from an rss feed, and it is converting what should be 'é' to 'é' when I actually print it out...

Any idea why this would be?
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

sounds like a character encoding thing to me - make sure it's the same all the way through
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Also make sure you tell the browser that the page being returned is encoded as UTF-8

Code: Select all

<?php
header('Content-type: text/html; charset=utf-8');
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>

<body>
.....
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

Bingo, that was it.. thanks!
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

I recommend you read my article on UTF-8 to understand what this charset business is all about. Interesting stuff and not too difficult to figure out.
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

Ambush, that's a good article, thanks.. I do however seem to still be having problems with data being entered in mysql. I set the character set to utf8, however storing the 'é' instead of 'é'

Any ideas?

Thanks!
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

A few things to ask:

1. Is the form submission page in UTF-8?
2. Is the MySQL column's encoding UTF-8?
3. How are you setting the connection encoding?
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

Well, reading more of your article i see that mysql v4 does not support character encoding, and i'm on 4.1
hmm.. guess I have to upgrade.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

4.0 doesn't support character encoding, but 4.1 does. No upgrading necessary.
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

Ah, well i wonder why it doesnt work... Let me answer your questions.

A few things to ask:

1. Is the form submission page in UTF-8?
Yes, I'm using php header and the characters are printing to the page properly


2. Is the MySQL column's encoding UTF-8?
Yes, I set the entire table to utf-8

3. How are you setting the connection encoding?
Not sure what this means, i'm just connecting using standard connection string.

Also to note, I print out the query, and it is showing the correct character in the insert statement, so i assume it is something with mysql. I'm also using innodb, if that makes a difference
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

Ahh, thank you! Works now... what a pain :)
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

For the sake of saving you some more pain later on, I'll inform you that PHP doesn't (yet) natively support UTF8... this problem will show itself when you begin using built-in string function on multi-byte strings. The mb_string extension is made for this purpose.
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

Nice, thanks a lot!
aaronhall wrote:For the sake of saving you some more pain later on, I'll inform you that PHP doesn't (yet) natively support UTF8... this problem will show itself when you begin using built-in string function on multi-byte strings. The mb_string extension is made for this purpose.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

I would recommend using phputf8 rather than mb_string directly. phputf8 contains fast, pure-PHP implementations of the string functions for when mb_string isn't available, and uses mb_string when it is.
Post Reply