Re: binary file + fread
| From: | Paul A. Procacci | Date: | Sun, 27 Jan 2002 16:43:43 +0000 |
| Subject: | Re: binary file + fread | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-82294@lists.php.net to get a copy of this message | ||
Try
<?php
$filename = "/export/html/log";
$fd = fopen( $filename, "rb" ); //Notice the "b"
$a = fread( $fd, 4 );
$b = fread( $fd, 4 );
printf( "a= %lx b=%lx", $a, $b);
fclose( $fd );
?>
notice the "b" in the fopen, it stand for binary.
Paul
Michael Agbaglo wrote:
> Hi !
>
> I've some trouble w/ the following peace of code... Althoug the file
> doesn't contain zeros at the beginning the output is
> a= 0 b=0
>
> Is there a problem w/ fread ? (php 4.0.6, RedHat 7.2)
>
> <?php
> $filename = "/export/html/log";
> $fd = fopen( $filename, "r" );
> $a = fread( $fd, 4 );
> $b = fread( $fd, 4 );
> printf( "a= %lx b=%lx", $a, $b);
> fclose( $fd );
> ?>