Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- size of binary string on multi-byte system?
February 3, 2005, 7:22 pm
rate this thread
normally, if you are given binary data in a string (such as from a call to
fread), you can call the strlen function on this string to get its size:
$buffer = fread($file, 100000);
if (strlen($buffer) < 100000)
echo "read less than 100000 bytes";
now, the problem is, on systems where you have the mbstring extension
turned on, and are using function substitution to replace strlen with
mb_strlen, you are pretty much guaranteed to get a WRONG value back from
strlen, since it will find some multi-byte lead characters in that binary
so the question is:
are there any other methods to find the length of a string besides strlen?
the only way i can see to not screw myself right now is to not use function
substitution. any other options?
I am not an ANGRY man. Remove the rage from my email to reply.
Re: size of binary string on multi-byte system?
I'd guess that "mb_strlen($str,'8bit')" would give you the actual
number of bytes in the string.
Checking.... http://nl3.php.net/mb_strlen the only comment:
If you wish to find the byte length of a multi-byte string when you are
using mbstring.func_overload 2 and UTF-8 strings, then you can use the
latin1 is also a 8bit encoding, only there are ranges not defined:
8bit sounds better IMHO.