Part of the EllisLab Network
   
1 of 2
1
Problems with accents and special characters
Posted: 10 July 2008 04:47 PM   [ Ignore ]  
Lab Assistant
Avatar
RankRank
Total Posts:  241
Joined  04-11-2008

Hi guys
I’ve been developing a CI app, and now I’m facing some implementation/testing problems
It is about accents and some special spanish characters like Ñ

- My config/database.php has this value

$db['default']['dbcollat'"utf8_general_ci"

- My database and tables were created as “utf8_general_ci”

When I add a new record to the table, with an accent, The record gets saved, but it looses all the characters after the accent (including the accented char.)

Also, the special characters aren’t stored.

What should I change? Both, database.php and my db/tables are using the same coll.

EDIT: Can this be generating some conflict?

<meta http-equiv="content-type" content="text/html;charset=iso-8859-1" /> 

Thanks a lot in advance for any help you can give me

 Signature 

Joomla! and custom web apps

Profile
 
 
Posted: 10 July 2008 06:12 PM   [ Ignore ]   [ # 1 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  165
Joined  08-22-2006

Hey, un argentino! Te respondo en cordobé raspberry

El juego de caracteres debe ser siempre el mismo, si tenes seteado el “content-type” en iso-8859-1 y el contenido a mostrar está en UTF-8 vas a tener problemas de visualización.

Igualmente lo que mencionas parece ser un problema a la hora de guardar los datos en la base de datos, fijate que los archivos PHP que están procesando la data estén en UTF-8 también y que no estés corriendo ninguna función que modifique la cadena de texto antes de guardarla en la base de datos.

 Signature 

Don’t argue with an idiot, people watching may not be able to tell the difference.


marcoss
http://defmay.com
http://fenix.st

Profile
 
 
Posted: 10 July 2008 07:01 PM   [ Ignore ]   [ # 2 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  241
Joined  04-11-2008

[SPANISH]
Hola compatriota!
Asi es, el problema es al guardar la info, si guardo en el registro “carámba”, solo se graba “car”. No entendi a que te referis con que los archivos que esten procesando la data esten en UTF-8…
Los nombres de los controladores, modelos, y vistas, no los tengo con caracteres extraños (si es eso a lo que te referis)
Y ademas, no tengo ninguna funcion que modifique la data que posteo. Del formulario va al controlador, y del controlador al modelo, sin nada que lo procese en el camino

[ENGLISH]
Hi marcoss!
You’re right, the problem is when saving the info. If I post “carámba”, it only saves “car”. I didn’t understand what you mean with “Check that the php files that process the data are also in UTF-8…
The filenames of controllers, models, and views doesn’t have strange characters (if this is what you mean)
And by the way, I don’t have any function that modifies the posted data. I post the form fields to the controller, then send them to the model, and there’s nothing in the middle that process that info

Gracias!/Thanks!

 Signature 

Joomla! and custom web apps

Profile
 
 
Posted: 10 July 2008 07:24 PM   [ Ignore ]   [ # 3 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  165
Joined  08-22-2006

By UTF-8 encoded files, i mean the files must be saved using that character set. What IDE/editor are you using?

 Signature 

Don’t argue with an idiot, people watching may not be able to tell the difference.


marcoss
http://defmay.com
http://fenix.st

Profile
 
 
Posted: 10 July 2008 07:36 PM   [ Ignore ]   [ # 4 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  241
Joined  04-11-2008

Dreamweaver 8 on WinDorcha XP…

 Signature 

Joomla! and custom web apps

Profile
 
 
Posted: 10 July 2008 07:45 PM   [ Ignore ]   [ # 5 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  165
Joined  08-22-2006

The problem is DW then raspberry

Make sure every document is on UTF-8, while you are on the code view, press Ctrl+J, go to Title/Encoding and select Unicode(UTF-8) from the encoding drop-down menu.

 Signature 

Don’t argue with an idiot, people watching may not be able to tell the difference.


marcoss
http://defmay.com
http://fenix.st

Profile
 
 
Posted: 10 July 2008 08:02 PM   [ Ignore ]   [ # 6 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  241
Joined  04-11-2008

Ouch… argggh
I tried your tip. I’ve not tried adding data to db yet, but so far I’m getting this little black symbols in the html, lol… this is going 2 ruin my weekend

http://img525.imageshack.us/my.php?image=sshot1hy9.jpg

 Signature 

Joomla! and custom web apps

Profile
 
 
Posted: 10 July 2008 08:59 PM   [ Ignore ]   [ # 7 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  550
Joined  10-18-2006

If that’s the problem, just htmlentities it =)
Luckily all spanish characters are escaped via html entities
I though it wasn’t saving OK into the database…

-Edit- post nº 700 =)

 Signature 

Once in a while I remember I use Twitter

Profile
 
 
Posted: 10 July 2008 10:40 PM   [ Ignore ]   [ # 8 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  165
Joined  08-22-2006

If that’s the data already in the database (which based on your explanation is incorrectly encoded) and you have now fixed the files encoding, it’s normal to have those symbols, once you have all your data in UTF-8 you won’t see that again.

Regarding htmlentities, don’t use it, it’s not portable. What you can do if you want to force the data entered in the database to be UTF-8 encoded, use utf8_encode() on it. Always keep your data in the same charset, choose one and stick to it.

p/d: Otro argentino!

 Signature 

Don’t argue with an idiot, people watching may not be able to tell the difference.


marcoss
http://defmay.com
http://fenix.st

Profile
 
 
Posted: 10 July 2008 10:50 PM   [ Ignore ]   [ # 9 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  550
Joined  10-18-2006

Somos varios, che…

I don’t think the data is incorrectly encoded at all… I believe it’s storing properly into the database, and the problem is when it’s displayed in a website… I don’t understund why you sayd it is not portable… as a matter of fact, html entities exists for that purpose

 Signature 

Once in a while I remember I use Twitter

Profile
 
 
Posted: 10 July 2008 11:49 PM   [ Ignore ]   [ # 10 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  165
Joined  08-22-2006

htmlentities will convert all applicable characters to HTML entities, it WILL NOT do character encoding/decoding, the reason it exists is to translate spacial character to their corresponding HTML entities.

However, it may work sometimes as you point, but that is because the function accepts a third parameter ($charset) which if not specified, will default to ISO-8859-1, so the output is returned that way (forced).

 Signature 

Don’t argue with an idiot, people watching may not be able to tell the difference.


marcoss
http://defmay.com
http://fenix.st

Profile
 
 
Posted: 11 July 2008 09:22 AM   [ Ignore ]   [ # 11 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  241
Joined  04-11-2008

Seppo
I can’t htmlentity automatically the user input in my forms… can I ?
Congrats for your 700th post

Also, found this “fix” but didn’t work… :( I’m so frustrated
http://www.lorztech.com/2008/06/unable-to-set-database-connection.html

============

Edit: I’ve found this interesting article
http://www.davidtan.org/differences-between-utf8_unicode_ci-and-utf8_general_ci/

I got astoonished when I read:

utf8_general_ci is a very simple collation. What it does - it just
- removes all accents
- then converts to upper case
and uses the code of this sort of “base letter” result letter to compare.

But changing the values in database.php, and tables to another collation, don’t work

 Signature 

Joomla! and custom web apps

Profile
 
 
Posted: 11 July 2008 10:08 AM   [ Ignore ]   [ # 12 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  241
Joined  04-11-2008

Guys
I’ve seen something that may be the cause of all this conflicts… am i right?
Check:
http://img154.imageshack.us/img154/7966/sshot1bs9.jpg

Also, doing this in dreamweaver for the header_view.php file (Ctrl+J, go to Title/Encoding and select Unicode(UTF-8) from the encoding drop-down menu.) helped, but

- How do I know if my .php source file is in UTF-8 ?
- Does this assure me that uploading the entire application/db will work on any shared hosting ?

Thanks a lot again…

 Signature 

Joomla! and custom web apps

Profile
 
 
Posted: 13 October 2008 11:52 PM   [ Ignore ]   [ # 13 ]  
Lab Assistant
RankRank
Total Posts:  225
Joined  06-04-2007

ok, yo no soy argentino…. pero tengo el mismo problema…

 Signature 

http://www.asinox.net
CodeIgniter code and more.

Profile
 
 
Posted: 01 November 2008 09:10 PM   [ Ignore ]   [ # 14 ]  
Lab Assistant
RankRank
Total Posts:  225
Joined  06-04-2007

ok i fixed!.

Entonces las unicas cosas que tuve que hacer:

DB Collation: utf8_general_ci

<html lang=“es”>

y claro <meta http-equiv=“Content-Type” content=“text/html; charset=utf-8” />

Saludos

 Signature 

http://www.asinox.net
CodeIgniter code and more.

Profile
 
 
Posted: 08 December 2008 05:34 PM   [ Ignore ]   [ # 15 ]  
Summer Student
Total Posts:  1
Joined  12-02-2008

Hola, estoy teniendo el problema de los acentos, tengo dos versiones de CI , la 1.3 y la 1.7 y en la v1.3 no encuentro como poner a funcionar los acentos , hice el asunto de modificar el header y nada .

Profile
 
 
   
1 of 2
1