note 30924 added to ref.filesystem
| From: | regis at webstuff dot com dot br | Date: | Thu, 03 Apr 2003 13:49:37 +0000 |
| Subject: | note 30924 added to ref.filesystem | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-46168@lists.php.net to get a copy of this message | ||
Here is a useful function if you're having trouble writing raw bytes into a file.
It receives an integer and returns an array containing the ASCII values of the bytes on each index
of the array.
function int2bytes($number){
$byte = $number;
$i=0;
do{
$dec_tmp = $byte;
$byte = bcdiv($byte,256,0);
$resto = $dec_tmp - (256 * $byte);
$return[] = $resto;
} while($byte >= 256);
if($byte) $return[] = $byte;
return array_reverse($return);
}
Example:
$arr = int2bytes(75832);
$arr will contain the following values:
Array
(
[0] => 1
[1] => 40
[2] => 56
)
Now, to write this data to the file, just use a fputs() with chr(), just like this:
fputs($fp,chr($arr[0]).chr($arr[1]).chr($arr[2]))
-- Regis
--
http://www.php.net/manual/en/ref.filesystem.php
http://master.php.net/manage/user-notes.php?action=edit+30924
http://master.php.net/manage/user-notes.php?action=delete+30924
http://master.php.net/manage/user-notes.php?action=reject+30924