Архив метки: utf

Валидируем UTF-ые строки в Yii

Начиная с версии 1.1.1 CStringValidator может принимать параметр «encoding». Выдержка из API:

the encoding of the string value to be validated (e.g. ‘UTF-8’). Setting this property requires you to enable mbstring PHP extension. The value of this property will be used as the 2nd parameter of the mb_strlen() function. Defaults to false, which means the strlen() function will be used for calculating the length of the string.

Используйте его при валидации текстовых строк на русском языке.

Пример (часть метода rules модели):

array(‘question, answer’, ‘length’, ‘max’=>255,’encoding’ => ‘utf-8’),

И не забудьте прочитать статью о том, как включить поддержку Юникод в Yii