User Tools

Site Tools


uphp:functions:fwrite_pack

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

uphp:functions:fwrite_pack [2021/01/28 09:57]
admin
uphp:functions:fwrite_pack [2021/09/13 05:57]
Line 1: Line 1:
-======fwrite_pack====== 
- 
-<badge>WMMEGA FW >= 2.1179</badge> 
- 
-Write data from an indexed array in binary form (packed) to a file. 
- 
-====Description==== 
- 
-<well size="sm"><html> 
-<span style="font-size:125%;color:green">int 
-<span style="color:black">fwrite_pack ( 
-<span style="color:green">int 
-<span style="color:blue">$handle<span style="color:black">, 
-<span style="color:green">indexed array 
-<span style="color:blue">$array 
-<span style="color:black">, 
-<span style="color:green">int 
-<span style="color:blue">$length<span style="color:black"> 
-) 
-</html></well> 
- 
-This function performs a binary-safe write of array data.  The data type is determined by the indexed array definition and can be: BYTE, SHORT, INT or FLOAT.  This is an efficient way to write multiple binary bytes to a file in one go. 
- 
-====Parameters==== 
- 
-<html><b><span style="color:blue">$handle<span style="color:black"></b></html>:  Valid handle of a previously opened file 
- 
-<html><b><span style="color:blue">$data<span style="color:black"></b></html>:  The indexed array data to be written.  
- 
-<html><b><span style="color:blue">$length<span style="color:black"></b></html>:  Number of elements to write (this will be multiplied by the array element size in byte which could be 1,2 or 4 depending on the data type) 
- 
- 
-====Return Values==== 
- 
-<html><b><span style="color:green">Integer<span style="color:black"></b></html> **number of bytes successfully written** 
- 
-====Examples==== 
- 
-<code php> 
-<? 
-  $fh = fopen("/fwrite_test.txt","w"); 
-  if (!$fh) { 
-    print("File open failed"); 
-  } else { 
-    $arr=indexed_array(4,10);  // create array of 10 floats 
-    for ($i=0;$i<sizeof($arr);$i++) { 
-      $arr[$i]=$i; 
-    } 
-    fwrite_pack($fh,$arr,sizeof($arr)); // this will write 40 bytes (10 elements * 4 bytes) 
-    fclose($fh); 
-  } 
-?> 
-</code> 
- 
- 
- 
-====See Also==== 
- 
-[[pack()]] - Pack data 
- 
-[[unpack()]] - Unpack data 
- 
-[[read_unpack()]] - Read binary data into an indexed array 
  
uphp/functions/fwrite_pack.txt · Last modified: 2021/09/13 05:57 (external edit)