Xxdfilename can display the binary form of a file on the terminal without considering the encoding of the file. How to use php to implement the same function? 1. fopen2.fread3. ehco does not work. it cannot display the binary value of the text. The text is displayed. how can this problem be solved? I wrote a paragraph... xxd filename
You can display the binary form of a file on the terminal without considering the encoding of the file.
How to use php to implement the same function?
1. fopen
2. fread
3. ehco does not work. The binary text cannot be displayed. The text is displayed. how can this problem be solved?
I wrote a piece of code
No. the character itself is displayed, not the binary expression of the character.
This ehco is expected to be modified. how can this problem be modified.
Fwrite (STDOUT, $ byte); replace echo $ byte; neither.
The modification is not far from success.
Test xxd-B./test.txt 0000000: 00001010 using a file containing only the line feed key. the program running result is: 10100.
Reply content:
Xxd filename
You can display the binary form of a file on the terminal without considering the encoding of the file.
How to use php to implement the same function?
1. fopen
2. fread
3. ehco does not work. The binary text cannot be displayed. The text is displayed. how can this problem be solved?
I wrote a piece of code
No. the character itself is displayed, not the binary expression of the character.
This ehco is expected to be modified. how can this problem be modified.
Fwrite (STDOUT, $ byte); replace echo $ byte; neither.
The modification is not far from success.
Test xxd-B./test.txt 0000000: 00001010 using a file containing only the line feed key. the program running result is: 10100.
Change the basic mode of the fopen mode parameter to B, as shown in figurerbTo distinguish between binary streams and text files.
You can also use 'B' to force the binary mode to avoid data conversion. To use these tags, either 'B' or 'T' is used as the last character of the mode parameter.
Perform base64 encoding on the server side and base64 decoding on the client side
Use PHP to output input streams for operations
Function strToTwo ($ str) {$ res = ''; $ len = strlen ($ str); for ($ I = 0; $ I <$ len; $ I ++) {$ tmp = base_convert (ord ($ str [$ I]), 10, 2); $ res. = $ tmp. '';} return trim ($ res);} var_dump (strToTwo (" Yan "));
UTF-8 encoded. This time is correct.