Ask how to convert the data into this form

Source: Internet
Author: User
How can I convert the data into this form?
This seems to be binary. what function does PHP use to convert a string or an array to this?

Share to:


------Solution--------------------
Pack ()
Reverse is unpack ()
------Solution--------------------
If you can do it with a pack, it's weird.
------Solution--------------------
The string is the binary
A indicates that the insufficient portion is filled with null (0x00) in the specified length
A means that in the specified length, the insufficient portion is filled with a space (0x20)
If you don't specify a length, it doesn't make any sense.
$s = ' CSDN (www.csdn.net) ';
for ($i =0; $i
printf ('%02x ', ord ($s {$i}));
if (($i + 1)%16 = = 0) echo '
';
}
4e (2e) 6e 2e 6e 65
74 29
------Solution--------------------
Lao Xu's length refers to the length of the format parameter, not the string (input).
Examples of manuals such as
Example #1 Pack () Example
$binarydata = Pack ("nvc*", 0x1234, 0x5678, 65, 66);
?>
The resulting binary string would be 6 bytes long and contain the byte sequence 0x12, 0x34, 0x78, 0x56, 0x41, 0x42.
Since the parameters N and v are 16 bits, and C is 8 bits, so the following parameters 0x1234 by the n parameter, 0x5678 by the V parameter, 65 by the C parameter, the * number indicates the subsequent continuation of the C parameter, so 66 also press the C parameter output
In other words, the * number in the format parameter can be used for an indefinite length of input.
  • 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.