Imagine this: I've an UTF-8 file and...

Imagine this: I've an UTF-8 file and...

by Eloy Lafuente (stronk7) -
Number of replies: 0
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Peer reviewers Picture of Plugin developers Picture of Testers
Hi all,

I would like to introduce you to one problem to see if there is any standard solution to solve it and to be able to apply it in different places across Moodle.

I've one UTF-8 file I've loaded into a PHP variable. Call it $originaltext.

Now I want to send it both to DB and to the browser without losing anything. I can imagine this situations:

  1. DB is set to UTF-8 and browser is set to UTF-8
  2. DB is set to ISO-8859-1 and browser is set to ISO-8859-1
  3. DB and browser have different charsets (but only UTF-8 and ISO-8859-1 combinations)
  4. DB or browser has non UTF-8 nor ISO-8859-1 charsets.


Now the questions:

  1. Are all of the above possible? Can I ignore any of them?
  2. Is there other possible combinations?
  3. How can I know both the DB and browser charsets being used? I know that, in some places the user->charset is used but, is this enough stable? Shouldn't it go to some more central and unalterable place? Once specified it should be easier to implement "translations" everywhere, I think.
  4. It seems to be different alternatives to do the work (mbstring, iconv, utf_decode...) but I would like to know if somebody have worked with this issue under other applications (OpenSource and PHP preferred, of course). Any suggestions?


This is only the first approximation to the problem, trying to know what charsets are intended to co-exist in Moodle and how to manage them. Any idea or comment will be welcome. Sure that, once the bases (objectives) were stabilised (approved) we could continue talking with more details about things like the UTF-8 transition, lang files and so on, so please, don't hurry up too much in this discussion. wink

Ciao smile
Average of ratings: -