Jump to content

Escape European Characters


ayok

Recommended Posts

Hi,

 

I'm trying to insert european characters to mysql such as ë, é, etc. However I've got strange character in my database. How can I encode this chars into html like &euml, or &eacute? I used code like

 

echo str_replace("ë","ë",$txt);

But it's not working.

 

Would anyone help?

 

thank you,

ayok

Link to comment
Share on other sites

And have you set the encoding properly? Just give UTF-8 encoding to:

 

1. MySQL connection:

 

SET NAMES 'utf8';

 

2. MySQL columns (collations), tables and database.

3. Set the website charset:

 

header('Content-type: text/html;charset=utf-8');

 

Or maybe you HAVE set UTF-8 in the database, but you haven't for the rest of the PHP script. Anyway, I think the problem comes from the fact that you have forgotten or do not understand the concept of character encodings.

 

echo str_replace("ë","ë",$txt);

 

It is not supposed to work, if you saved the script in ISO-8859-1 and you try to convert texts i.e. in UTF-8. And I DO NOT recommend converthing them to entities. They will work in nothing but HTML and moreover, the entities do not cover ALL european characters.

Link to comment
Share on other sites

Thank you Zyx,

 

No, i think i still don't understand the concept of character encodings. On the top of my index.php there is <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />, is that not enough?

 

So what's should I better do? I use phpmyadmin, and I see the column "collation" if I make a new table. Should I set this to utf8_unicode_ci?

Link to comment
Share on other sites

Collation should be set to utf8 yes. You will also need..

 

mysql_query("SET NAMES 'utf8'");

 

... and possibly...

 

mysql_query("SET CHARACTER SET 'utf8'");

 

...directly after connecting to your database for it to work. Combined with the HTML meta tag you have that should fix it.

Link to comment
Share on other sites

No, in case of UTF-8, most browsers ignore the META tags - this is why you must send a HTTP header, as I said:

 

header('Content-type: text/html;charset=utf-8');

 

Ad. MySQL collations. Actually, utf8_unicode_ci is enough for most of people on the planet. It specifies the general sorting order for UTF-8 strings according to the national characters. The other collations are just the extensions of the general UTF-8 collation that apply some extra language-specific sorting rules. For example, French is perfectly covered by utf8_unicode_ci and it does not require any special collation. On the other hand, Polish has such rules and it has its own collation: utf8_polish_ci. And because this is an extension, it still works perfectly for French.

 

cags -> SET NAMES 'utf8' is enough for a connection :).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.