PHP, how string to byte array?

Source: Internet
Author: User
Keywords Php
https://segmentfault.com/q/1010000004223227?_ea=534609

Find an answer here but don't understand why it's unpack instead of pack

Reply content:

https://segmentfault.com/q/1010000004223227?_ea=534609

Find an answer here but don't understand why it's unpack instead of pack

Take a good look at it, this should be very understood.

A string in PHP
is implemented by a byte array plus an integer indicating the length of the buffer. There is no information on how to convert bytes into characters, as determined by the programmer. There is no limit to what values a string consists of, and, in particular, its value is
0 ("NUL bytes") bytes can be anywhere in the string (although there are several functions that are referred to in this manual as non-"binary security", it may be NUL
The data after the byte is ignored).

This attribute of the string type explains why there is no separate "byte" type in PHP-it has been replaced with a string. Functions that return non-literal values-
For example, any data read from a network socket-the string will still be returned.

Above excerpt from manual http://php.net/manual/zh/language.types.string.php

PHP inside a string is a byte array, do not convert, the general transmission of the number type only need pack.

The array subscript generated by unpack is starting from 1, not starting from 0, which is a little odd.

  • 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.