php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #12332 Reading and Writing files
Submitted: 2001-07-24 05:55 UTC Modified: 2001-07-24 09:59 UTC
From: fred at surleau dot com Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.0.6 OS: All
Private report: No CVE-ID: None
 [2001-07-24 05:55 UTC] fred at surleau dot 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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-07-24 09:59 UTC] mfischer@php.net
You actually use pack() and unpack() to prepare binary data to be written or to be read, see their manual entries.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 09:01:26 2024 UTC