Bug #12332 Updated: Reading and Writing files
| From: | mfischer@php.net | Date: | Tue, 24 Jul 2001 13:59:26 +0000 |
| Subject: | Bug #12332 Updated: Reading and Writing files | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-60855@lists.php.net to get a copy of this message | ||
ID: 12332
Updated by: mfischer
Reported By: fred@surleau.com
Old Status: Open
Status: Closed
Bug Type: Feature/Change Request
Operating System: All
PHP Version: 4.0.6
New Comment:
You actually use pack() and unpack() to prepare binary data to be written or to be read, see their
manual entries.
Previous Comments:
------------------------------------------------------------------------
[2001-07-24 05:55:57] fred@surleau.com
Hi,
There is no fonction in PHP to read or write an integer or a long value from a file.
Actually, I read a 2 or 4 characters string, and convert it into the corresponding numeric value
with this function :
function readNum( $f, $len )
{
$tmp = strrev( fread( $f, $len ) );
$val = 0;
for( $i=0; $i<$len; $i++ )
$val += ord(substr($tmp,$i,1)) * pow(256,$len-1-$i);
return $val;
}
Regards,
Fred.
------------------------------------------------------------------------
Edit this bug report at http://bugs.php.net/?id=12332&edit=1