Jump to content

Recommended Posts

Hi

 

I'm a noobie to PHP and although the language seems fairly straightforward I'm not quite sure what the best approach to this problem may be.

 

I'm uploading a compressed file containing a variety of data types. I need to decompress the file and make the variables available to the php script. The file will get changed once a day.

 

At the moment I can upload and decompress the file. Assigning the strings is straightforward.

 

The real concern is how to convert the integers and floats to the format used by php.

 

The only way I can think of doing this is to upload them as ascii strings and do the conversion as required.

 

This seems pretty naff. I would prefer to do any conversion required on the numbers client side as it would speed up the script.

 

Any help, advice or ideas much appreciated. Client is running XP and the number generating program is written in Delphi.

 

Best Regards

 

Picclock

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/64877-advice-needed-on-variable-transfer-type/
Share on other sites

Hi

 

The only data types involved are integers and floating point values. I would like to store them in arrays.

 

The strings are easily dealt with (I will just seperate them with comma's [csv] and read them directly into an array. 

 

The values will be used for graph generation - which I've managed to do thanks to some excellent web tutorials.

 

What I would like to do is something similar to a blockload where I can load the arrays in one file read rather than go through the tedious and slow business of saving the numbers as strings then converting the strings to numbers.

 

I am really trying to find out if there is a recognised or preffered method of transferring numerical data.

 

Best Regards

 

picclock

I'm still not 100% sure what you mean - maybe you should show us the uncompressed file.

 

If your file holds strings (text) and you can comma separate those, then why not : or ; separate the numbers (floating points and integers)?

 

<?php

//This line comes from the file in question and is obtained / read by fopen/fread
$number_line = "3;4.45;7.0000;18;900.75;10e7"

//As with csv explode and store in array
$numbers = explode($number_line,";");

//Now use the array and calculate something with your values
$result = $numbers[0] + $numbers[3] //21

?>

You don't think you have to worry about the datatypes.

Hi

 

This is a hex dump of an array of integers and text from a part of one of the uncompressed file :

0056e280h: 00 06 53 4D 4F 50 53 41 00 00 00 00 00 00 00 00 ; ..SMOPSA........

0056e290h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................

0056e2a0h: 00 00 00 00 00 00 00 00 11 2B 00 00 0D 2B 00 00 ; .........+...+..

0056e2b0h: B9 2A 00 00 C1 2A 00 00 F2 2A 00 00 25 2B 00 00 ; ¹*..Á*..ò*..%+..

0056e2c0h: 14 2B 00 00 EA 2A 00 00 F3 2A 00 00 D3 2A 00 00 ; .+..ê*..ó*..Ó*..

0056e2d0h: C5 2A 00 00 42 2B 00 00 66 2B 00 00 F4 2A 00 00 ; Å*..B+..f+..ô*..

0056e2e0h: E8 2A 00 00 2E 2B 00 00 F0 2A 00 00 83 2B 00 00 ; è*...+..ð*..ƒ+..

0056e2f0h: 8C 2B 00 00 A9 2B 00 00 A7 2B 00 00 C2 2B 00 00 ; Œ+..©+..§+..Â+..

0056e300h: 16 2C 00 00 D6 2B 00 00 E4 2B 00 00 FA 2B 00 00 ; .,..Ö+..ä+..ú+..

0056e310h: 75 2C 00 00 75 2C 00 00 6F 2C 00 00 4C 2C 00 00 ; u,..u,..o,..L,..

0056e320h: 3A 2C 00 00 34 2C 00 00 0D 2C 00 00 55 2C 00 00 ; :,..4,...,..U,..

 

As you can see the integers are stored in the native 4byte format (32 bit system). The floats are stored in an 8 byte format giving 16 digits of precision.

 

From your earlier reply is it possible that PHP internal number storage is done as strings of ascii characters ?

 

This would make any processing of mathematics very slow as the strings would have to converted to binary bytes, operated on and the result reconverted back to a string.

 

Please forgive my ignorance of PHP. Although I am well versed in a number of languages this is my first real attempt to write a script in it.

 

Best Regards

 

Picclock

 

 

 

 

 

 

I don't know very much about coding or programming besides PHP so again I must ask you to clarify :)

 

Are you looking for a way to perform mathematical operations with the numbers as they are or a way to convert them to decimal or?

 

I tried hexdec() and octdec() on "0056e280h" and "00 06 53 4D 4F 50 53 41 00 00 00 00 00 00 00 00" and it yielded decimal numbers....

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.