I’m quite new to Yii and currently working on my first project. As it is for a German user audience I need to use the German special chars like ‘ä,ü,ü,ß’. I would in common escape them by hand as e.g. ‘ä’ for ‘ä’. But unfortunately Yii would escape the ‘&’ char then - but it does not escape the German special characters.
Is there any way to either turn off automatically escaping (so the & char would not be escaped) or to add automatical escaping to the German special chars?
After analyzing everything I found out the best solution (at least for me):
Change the following function in the CHTML class:
public static function encode($text)
{
return htmlentities($text,ENT_QUOTES,Yii::app()->charset);
}
I replaced htmlencode() with htmlentities(). I see no need in replacing only the HTML-related stuff instead of everything. And migrating everything to UTF-8 is senseless as long as IE6 users are still out there
all files (localization files, models, controllers, views) should be utf-8 WITHOUT BOM
database should be utf-8 (collation utf-8-general-ci i.e.)
database connection should be utf-8
set names utf-8
If you work properly and carefully day by day, you will never have problem with encoding.
If you want, you can use another charset, but remember to change everithig accordingly.
I worked in italy for some year, and in italian like in german there are only a fiew special chars, so if it all looks correctly, you can avoid the problem.
As I moved in russia, I learned how to work correctly with encoding, here there are no possibility to “half solution”!