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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: fred at surleau dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 00:01:35 2025 UTC