kallaspriit/Cassandra-PHP-Client-Library

Unpack string

cmario opened this issue · 1 comments

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

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