Unpack string #2

Closed
cmario opened this Issue Aug 3, 2011 · 1 comment

Comments

Projects
None yet
2 participants
@cmario

cmario commented Aug 3, 2011

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

@ghost ghost assigned kallaspriit Aug 8, 2011

@kallaspriit

This comment has been minimized.

Show comment Hide comment
@kallaspriit

kallaspriit Aug 15, 2011

Owner

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

Owner

kallaspriit commented Aug 15, 2011

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

kallaspriit added a commit that referenced this issue Aug 15, 2011

Fixed issued #1 and #2
- integer columns handled correctly
- special character strings unpacked correctly

gwagner added a commit to gwagner/Cassandra-PHP-Client-Library that referenced this issue Aug 15, 2011

Fixed issued #1 and #2
- integer columns handled correctly
- special character strings unpacked correctly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment