note 51038 added to function.fread
| From: | james at reflexive dot net | Date: | Thu, 17 Mar 2005 18:22:25 +0000 |
| Subject: | note 51038 added to function.fread | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-86594@lists.php.net to get a copy of this message | ||
You will probably want to call unpack() if you are trying to read binary data out of a file and you
want to interpret the data you read (rather than just passing it through to a browser). For example,
if you were reading the header if a binary file format such as a BMP image file you would need to
read 4 byte integers out of the binary file. fread() will return the binary data in a string.
unpack() will let you extract data out of the string an use it as a number.
<?php
function Read32BitLittleEndianIntFromBinaryFile($FileHandle)
{
$BinaryData = fread($FileHandle, 4);
$UnpackedData = unpack("V", $BinaryData);
return $UnpackedData[1];
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.fread.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+51038
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51038&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51038&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51038&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51038&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51038&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+51038&report=yes
Search -- http://master.php.net/manage/user-notes.php