开发者

Storing foreign langage (i.e. non English) text in memcache

开发者 https://www.devze.com 2022-12-27 07:29 出处:网络
I am storing some text values in memcached. An example of such a string is: El Salvador (República De El Salv开发者_StackOverflow社区ador)

I am storing some text values in memcached. An example of such a string is:

El Salvador (República De El Salv开发者_StackOverflow社区ador)

When I attempt to retrieve the string, I get an empty string. I suspect this is something to do with UTF-8 strings. How may I store foreign language text in memcached?


I'm not a Unicode expert, but this piqued my curiosity so I wrote a little code:

http://static.bwerp.net/~adam/20100420/m.php

Seems to work reasonably well, over here. You said you thought it was a UTF-8 issue. What happens if you remove the accented character?

For posterity, here's the code in the linked file:

header('Content-type: text/html; charset=utf-8');

echo '<pre>';

$s = utf8_encode("El Salvador (Rep\xfablica De El Salvao)");
echo '$s = ', $s, '<br>';
var_dump( mb_detect_encoding($s) );

$m = new Memcache;
$m->addServer('localhost', 11211);

var_dump( $m->set('foobarcheeze', $s) );
var_dump( $m->get('foobarcheeze') );

echo 'strlen($s) = ', strlen($s), '<br>';
echo 'mb_strlen($s) = ', mb_strlen($s), '<br>';
echo 'mb_strwidth($s) = ', mb_strwidth($s), '<br>';
0

精彩评论

暂无评论...
验证码 换一张
取 消