Re: how to display the binary form of the file with php?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux