Re: how to display the binary form of the file with php?
| From: | Christoph M. Becker | Date: | Sat, 13 Aug 2016 14:26:41 +0000 |
| Subject: | Re: how to display the binary form of the file with php? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-325673@lists.php.net to get a copy of this message | ||
On 13.08.2016 at 03:08, 水静流深 wrote:
> Every file can be displayed in the binary form no matter which encoding the file is.(utf-8 gbk
> iso-8859-1 latin-1)
>
>
xxd filename can do the trick.
>
> Now i want to do with php,here is my try.
>
>
> <?php $target="test.txt"; $file_handle = fopen($target, "rb");
> while (!feof($file_handle)) { $byte = fread($file_handle,1); echo $byte; }
> fclose($file_handle ); ?>
> It is unlucky that all the character is not displayed on binary form,how to fix
> echo $byte ?
You can use echo dechex($byte); instead. printf() might be
preferable, though.
Note that reading a file bytewise might be rather slow in PHP. Consider
to read chunks of bytes instead.
--
Christoph M. Becker