note 27044 added to function.fputs

From: Date: Thu, 21 Nov 2002 10:03:12 +0000
Subject: note 27044 added to function.fputs
Groups: php.notes 
Request: Send a blank email to php-notes+get-39792@lists.php.net to get a copy of this message
Adding to Adam (Nedstat): fputs without the length parm just writes all data up to but not including the first 0 byte it encounters. Therefore fputs($fp,"hello\0world") will only write hello to $fp whereas fputs($fp,"hello\0world",11) will write both words. If this doesn't make sense for you, remember strings are always terminated with that 0 byte. Binary data doesn't have such a terminator byte as a 0 byte can be a completely valid piece of data therefore you always need to know the length of the binary datapart. BTW strlen() is binary safe, so you can use that to get the length of the binary data part as well - this is different from C which counts the number of chars up to the 0 byte. So the example above could also be written as: fputs($fp,"hello\0world",strlen("hello\0world")) -- http://www.php.net/manual/en/function.fputs.php http://master.php.net/manage/user-notes.php?action=edit+27044 http://master.php.net/manage/user-notes.php?action=delete+27044 http://master.php.net/manage/user-notes.php?action=reject+27044

« previous php.notes (#39792) next »