views:

146

answers:

1

I'm trying to save UTF-8 characters with Zend_Cache (like Ť, š etc) but Zend_Cache is messing them up and saves them as Å, ¾ and other weird characters.

Here is a snippet of my code that saves the data to the cache (the UTF-8 characters are messed up only online, when I try it on my PC on localhost it works ok):

// cache the external data
$data = array('nextRound' => $nextRound,
              'nextMatches' => $nextMatches,
              'leagueTable' => $leagueTable);
$cache = Zend_Registry::get('cache');
$cache->save($data, 'externalData');

Before I save the cached data, I purify it with HTMLPurifier and do some parsing with DOM, something like this:

    // fetch the HTML from external server
    $html = file_get_contents('http://www.example.com/test.html');

    // purify the HTML so we can load it with DOM
    include BASE_PATH . '/library/My/htmlpurifier-4.0.0-standalone/HTMLPurifier.standalone.php';
    $config = HTMLPurifier_Config::createDefault();
    $config->set('HTML.Doctype', 'XHTML 1.0 Strict');
    $purifier = new HTMLPurifier($config);
    $html = $purifier->purify($html);

    $dom = new DOMDocument();
    // hack to preserver UTF-8 characters
    $dom->loadHTML('<?xml encoding="UTF-8">' . $html);
    $dom->preserveWhiteSpace = false;

    // some parsing here

Here is how I initialize Zend_Cache in the bootstrap file:

protected function _initCache()
{
    $frontend= array('lifetime' => 7200,
                     'automatic_serialization' => true);
    $backend= array('cache_dir' => 'cache');
    $this->cache = Zend_Cache::factory('core',
                                       'File',
                                       $frontend,
                                       $backend);
}

Any ideas? It works on localhost (where I have support for the foreign language used in the HTML) but not on the server.