Chtml::encode bug ??

Hi @ all !

I’m trying to display a text that contains special characters without success.

@the view, if I type:


echo 'éééééé';

i see:


éééééé

on my webpage.

but when i type:


echo CHtml::encode('éééééé');

I don’t see anything (blank page).

Is it due to a line i should add to the main config file ? (like charset or something like)

Do you have configured the charset property? If not it defaults to UTF-8. So you should make sure that your application sends the right charset in your HTTP header. Also check here: http://www.yiiframework.com/doc/cookbook/16/

Should I have to add a line in the main config ?

because i would like to setup the application charset as ISO-8859-1

if I write on my template :


<?php echo Yii::app()->charset;?>

I get : ‘UTF-8’

But how i can change this value ?

Set it in your configuration (main.php):


return array(

  // ...

  'charset'=>'ISO-8859-1',

  ///...

);



OK thanks but i think I solved the special characters problem.

It was due to strtolower() function that does not supports conversion of special characters like ‘é’ or ‘ç’.

I solved this problem with a nice function I found at php.net :




    function utf8_strtolower($string) {

        return utf8_encode(strtolower(utf8_decode($string)));

    }

You could also use mb_strtolower(). See the mentioned cookbook.