> > > Enjoyed Andrei's talk at the NYPHP Conference last week > about unicode in > > PHP 6. He mentioned that when unicode.semantics is on, > strlen() will > > return the number of characters rather than the number of > bytes, like > > mb_string() does or strlen() if mbstring.func_overload is on. > > > > The hitch here is there are situations where one needs to > know how many > > bytes are in a string. Is there a function I've overlooked > that does > > this or will do this, please? > > > My first question is: Why do you need to know the number of > bytes occupied > by a textual string? Is it because you want to work with > binary strings? > Because that's still very possible: > > Even with unicode.semantics=on, the binary string type may be > explicitly > used in a few ways: > > $a = b"This string contains an 0xF0 byte: \xF0"; > $alen = strlen($a); > > This being the simplest, the lowercase b (or u) characters > denote a string > as being a binary (or unicode) string explicitly. Leaving > these specifiers > off yield whatever type is appropriate to unicode.semantics. > > In other cases, such as reading from a binary mode file: > > $fp = fopen('foo.bin', 'rb'); > $str = fread($fp, 100);
Hi, What happens with $fp = fopen('foo.bin', 'wb'); $written = fwrite($fp, $str); if (strlen($str) != $written) { echo 'Not written', "\n"; } Jared -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php