Home > Java > javaTutorial > body text

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

PHPz
Release: 2023-08-31 14:05:06
forward
1400 people have browsed it

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)
Copy after login

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)

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

      < /li>
    • 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);
?>
Copy after login

Output

The following is the output.

AMIT
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template