This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
uphp:functions:read_unpack [2021/01/28 10:09] admin removed |
— (current) | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ======fread_unpack====== | ||
- | |||
- | < | ||
- | |||
- | Read data from a file into an indexed array in binary form. | ||
- | |||
- | ====Description==== | ||
- | |||
- | <well size=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | ) | ||
- | </ | ||
- | |||
- | This function performs a binary-safe read of data from a file into an indexed array that is automatically created. | ||
- | |||
- | ====Parameters==== | ||
- | |||
- | < | ||
- | |||
- | < | ||
- | ^ Value ^ Description | ||
- | | l | signed long (always 32 bit, machine byte order) | ||
- | | f | floating point(always 32 bit, machine byte order) | ||
- | | c | signed byte | | ||
- | |||
- | < | ||
- | |||
- | < | ||
- | |||
- | ====Return Values==== | ||
- | |||
- | < | ||
- | |||
- | ====Examples==== | ||
- | |||
- | <code php> | ||
- | <? | ||
- | // assuming your file contains the following float: | ||
- | // 1.0, | ||
- | $fh = fopen("/ | ||
- | if (!$fh) { | ||
- | print(" | ||
- | } else { | ||
- | $arr=fread_unpack($fh,' | ||
- | // this will contain an array of 10 floating points read contiguously | ||
- | print_r($arr); | ||
- | // 1.0, | ||
- | | ||
- | $arr=fread_unpack($fh,' | ||
- | // this will contain an array of 10 floating point values spaced at 2 floats apart. | ||
- | | ||
- | print_r($arr); | ||
- | // 1.0, | ||
- | | ||
- | fclose($fh); | ||
- | } | ||
- | ?> | ||
- | </ | ||
- | |||
- | |||
- | |||
- | ====See Also==== | ||
- | |||
- | [[pack()]] - Pack data | ||
- | |||
- | [[unpack()]] - Unpack data | ||
- | |||
- | [[fwrite_pack()]] - Write binary data from an indexed array | ||