php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #6884 problem getting a double variable from binary file
Submitted: 2000-09-26 02:40 UTC Modified: 2000-10-25 14:03 UTC
From: heinrich at noiseconcept dot de Assigned:
Status: Closed Package: Variables related
PHP Version: 4.0.2 OS: Win2k/98/Redhat6.1
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: heinrich at noiseconcept dot de
New email:
PHP Version: OS:

 

 [2000-09-26 02:40 UTC] heinrich at noiseconcept dot de
Hi!

Probably this isn't a true bug, bit I couldn't find ANY
one (tried Newsgroups/IRC/Doc's..) who could explain this
to me:

I'm reading a price list from a file in which there are
(beyond other stuff) Product name and price saved.
Extracting the Product name is no problem but the price
is saved as a 8byte-double variable. So I used:
$price=unpack("d",substr($contents,211,8));
But this results in absolutely strange values like
8.3...+E-311 and so on. My file is valid since I've also
programmed this using Borland Delphi. There I use
the command "move" to move the part of the memory where
the file buffer is saved directly to the address of a
double variable. There it works quite fine. So - what's
wrong? (Although I'm KNOW that it's an 8byte double I
tried with any other decoding method from unpack like float,
single and so on... Nothing worked..

Please contact me If you know anything about that, it's
quite important for me :-}

Tnx a lot! - bye!


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-10-18 06:37 UTC] stas@php.net
Failed to reproduce the behaviour. Could you please provide a binary string that is decoded incorrectly by unpack?
Also, note that unpack has different syntax than in perl (see the manual) so  doesn't do what you want, you should do $price=unpack("dvar",...) and use $price["var"] then.
 [2000-10-25 14:02 UTC] derick@php.net
User reported:

I found the error - was my mistake. Sorry!

(In fact it WAS a wrong offset but Delphi autocorrected this mistake of mine
so I thought the settings were correct)

tnx anyway - bye!

Greets - Max.


 [2000-10-25 14:03 UTC] derick@php.net
And close
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue May 13 10:01:27 2025 UTC