0

Zend_Cache(Ť、šなど)を使用してUTF-8文字を保存しようとしていますが、Zend_Cacheがそれらを台無しにして、Å、3/4、およびその他の奇妙な文字として保存しています。

データをキャッシュに保存するコードのスニペットを次に示します(UTF-8文字はオンラインでのみ混乱します。ローカルホストのPCで試してみると、問題なく動作します)。

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

キャッシュされたデータを保存する前に、HTMLPurifierでデータを精製し、次のようにDOMで解析を行います。

    // 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

ブートストラップファイルでZend_Cacheを初期化する方法は次のとおりです。

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

何か案は?ローカルホスト(HTMLで使用される外国語をサポートしている)では機能しますが、サーバーでは機能しません。

4

1 に答える 1