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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

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: Sat Apr 27 12:01:29 2024 UTC