How to convert data in this form-php Tutorial

Source: Internet
Author: User
Tags example of manual
How can we convert data into this form? It seems to be binary. What function does php use to convert a string or array to this? Share to: how can I convert data in this form?
It seems to be binary. What function does php use to convert a string or array to this?

Share:


------ Solution --------------------
Pack ()
The reverse direction is unpack ()
------ Solution --------------------
If only pack can be used, that's strange.
------ Solution --------------------
The string is binary.
A indicates that in the specified length, the insufficient part is filled with null (0x00 ).
A indicates that in the specified length, the insufficient part is filled with spaces (0x20 ).
It makes no sense if no length is specified.
$s = 'CSDN(www.csdn.net)';
for($i=0; $i printf('%02x ', ord($s{$i}));
if(($i+1)%16 == 0) echo '
';
}
43 53 44 4e 28 77 77 2e 63 73 64 6e 2e 6e 65
74 29
------ Solution --------------------
The fixed length written by Xu refers to the length required by the format parameter, rather than the length of the string (input ).
Example of manual
Example #1 pack () example
$ Binarydata = pack ("nvc *", 0x1234, 0x5678, 65, 66 );
?>
The resulting binary string will be 6 bytes long and contain the byte sequence 0x12, 0x34, 0x78, 0x56, 0x41, 0x42.
Because the n and v parameters are 16 bits and c parameters are 8 bits, the following parameters 0 x are followed by the n parameter, 0x5678 is followed by the v parameter, and 65 is followed by the c parameter, * indicates that the c parameter will be followed, so 66 is also output according to the c parameter.
In other words, the * sign in the format parameter can be used for an input with an indefinite length.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.