After getting crazy last days with one Spanish moodler about how his site was showing accents and other chars (only in some places, apparently in a random fashion) I discovered that it had the tidy filter enabled and running.
So, one simple string like this:
after being processed by format_text() is showed in browser like:
(enclosed by html <p> tags in source code)
It seems that tidy breaks things sometimes...
1) Enable tidy filter (ensure you've installed the PHP5 tidy extension (tidy_repair_string).
2) Copy the attached test.php to your moodle dirrot.
3) Invoke it from the browser.