drcelus
drcelus

Reputation: 479

Size of a PHP string that can contain any type of data

I want to check the size of a string that can contain any type of data. I have checked strlen and mb_strlen but I am unsure about the differences relating to different data contents.

Some background : what I need to do in the end is cut the string in chunks to serialize it and store it in chunks (being able to restore afterwards). Chunks always have the same size (32Kb) and contain a serialized object with data and the part of the string that I cut, so I need the exact size of the string to be able to do that.

Upvotes: 0

Views: 81

Answers (1)

GordonM
GordonM

Reputation: 31780

From PHP's manual:

Note:
strlen() returns the number of bytes rather than the number of characters in a string.

By contrast, mb_strlen will take character encoding into consideration. It returns the number of actual characters as defined in the character encoding in the string. For multibyte/variable byte character encodings, strlen can/will be bigger than mb_strlen.

mb_strlen may also return FALSE if you specify a character encoding to which the string being tested doesn't conform.

Upvotes: 2

Related Questions