kallaspriit / Cassandra-PHP-Client-Library

Cassandra PHP-based client library for managing and querying your Cassandra cluster
http://cassandra-php-client-library.com
103 stars 25 forks source link

Unpack string #2

Closed cmario closed 13 years ago

cmario commented 13 years ago

Hi,

I've a problem with some char like 'è' or 'ù' when I read data from cassandra. The code that unpacks the string is the follow:


public static function unpackString($value, $length)  {
        $unpacked = unpack('c'.$length.'chars', $value);
        $out = '';

        foreach($unpacked as $element) {
            if($element > 0) {
                $out .= chr($element);
            }
        }

        return $out;
}

If I replace 'c' with 'C' (unsigned char), this solve the problem.

I'd to like to know which is the sense to split a string into characters and then join characters into a string.

Thanks in advance Mario

kallaspriit commented 13 years ago

Made a test for it and you are correct, such characters were not handled properly. Using unsigned char solved the problem :)