Home  >  Article  >  Java  >  In PHP, the function of pack() function is to convert data into binary string

In PHP, the function of pack() function is to convert data into binary string

PHPz
PHPzforward
2023-08-31 14:05:061396browse

In PHP, the function of pack() function is to convert data into binary string

pack() function packs data into a binary string.

Syntax

pack(format , args)

Parameters

  • Format - The format to use. The following are the possible values ​​-

    • a - NUL padded string

    • A - Space padded String

    • h - Hexadecimal string, low nibble first

    • H - Hexadecimal string, high nibble first

    • c - Signed character

    • C - Unsigned character

    • s - Signed short character (always 16 bits, machine byte order)

    • S - unsigned short (always 16 bits, machine byte order)

    • n - Unsigned Short (always 16 bits, big endian)

    • v - Unsigned Short (always 16 bits) , little-endian byte order)

    • i - signed integer (depends on machine size and byte order)

    • I - unsigned integer (depends on machine size and byte order)

    • l - signed long (always is 32 bits, machine byte order)

    • L - unsigned long (always 32 bits, machine byte order)

      li>
    • N - unsigned long (always 32-bit, big-endian)

    • V - unsigned long (always is 32-bit, little-endian)

    • f - float (depends on machine size and representation)

    • d - double precision (depends on machine size and representation)

    • x - NUL byte

    • X - Back up one byte

    • Z − NUL padding string

    • @ − NUL padded to absolute position

  • args - One or more arguments to be packed.

Return

The pack() function returns a binary string containing data.

Example

Real-time demonstration

<?php
   echo pack("C3",80,72,80);
?>

Output

The following is the output.

AMIT

The above is the detailed content of In PHP, the function of pack() function is to convert data into binary string. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete