Does anyone know how to get the bit length of a string in PHP? Thanks.
- Josh
Does anyone know how to get the bit length of a string in PHP? Thanks.
- Josh
Reply With Quote
Reply With Quote
I'm trying to determine the amount of space a string takes up in bytes. I know how to do it in MySQL:
That will give me the number of bytes for "blobfieldname" where "user_id" is equal to 1.Code:SELECT SUM(BIT_LENGTH(blobfieldname)) FROM DATA WHERE user_id=1
Oh, and strlen wouldn't work because a character does not exactly represent a byte.
Reply With Quote
Reply With Quote
Reply With Quote If you know the 'width' of a character, then can't you determine its size in bytes from its length? For example, an ASCII character is 8-bit, so if you have a string "hello" in ASCII, is it not 40 bits wide? Maybe there are subtleties of character encoding that I have no idea about.
Mike
Reply With Quote
Reply With Quote