Search code examples
zend-frameworkencodingzend-validate

set global encoding in Zend Framework


My bootstrap sets encoding for all views:

protected function _initView () {
    $view = new Zend_View();
    // snip...
    $view->setEncoding('utf-8');
    // snip...
    return $view;
}

However, this does not set encoding for my form validators. The StringLength uses its default encoding (I'm not sure which that is) and it counts diacritics as two characters.

I know I can set the 'encoding' => 'utf-8' option when creating the validator, but it's kind of pesky to update all validators across my entire (huge) application. Is there a way to set the encoding for all validators at the same time?


Solution

  • In ZF 1.1x the StringLength validator uses iconv_strlen:

    int iconv_strlen(string $str [, string $charset = ini_set("iconv.internal_encoding")])
    

    So one thing to try is to call ini_set (or iconv_set_encoding('internal_encoding', $encoding);).