Hey whats up? I just got my wisdom teeth pulled today so I have plenty of time to read all my books and get refreshed again with PHP. Now I have a question..I am working on a highly secure system that will hopefully help everyone make their systems much more secure. I was wondering though...is there a simple prebuilt function that can take a text string and turn it into Binary? I have looked in my books and cant find anything that can help me. bin2hex(string) is something close but takes a binary form and makes it ASCII hex. Well that wouldn't spell anything. Since its on a base 16 and not on a base 26. Any ideas? I will be more than happy to place your name in the credits. Thanks!
Ziggs

    This might work:

    Description

    string pack ( string format [, mixed args])
    Pack given arguments into binary string according to format. Returns binary string containing data.

    The idea to this function was taken from Perl and all formatting codes work the same as there, however, there are some formatting codes that are missing such as Perl's "u" format code. The format string consists of format codes followed by an optional repeater argument. The repeater argument can be either an integer value or * for repeating to the end of the input data. For a, A, h, H the repeat count specifies how many characters of one data argument are taken, for @ it is the absolute position where to put the next data, for everything else the repeat count specifies how many data arguments are consumed and packed into the resulting binary string. Currently implemented are

    a NUL-padded string

    A SPACE-padded string

    h Hex string, low nibble first

    H Hex string, high nibble first

    c signed char

    C unsigned char

    s signed short (always 16 bit, machine byte order)

    S unsigned short (always 16 bit, machine byte order)

    n unsigned short (always 16 bit, big endian byte order)

    v unsigned short (always 16 bit, little endian byte order)

    i signed integer (machine dependent size and byte order)

    I unsigned integer (machine dependent size and byte order)

    l signed long (always 32 bit, machine byte order)

    L unsigned long (always 32 bit, machine byte order)

    N unsigned long (always 32 bit, big endian byte order)

    V unsigned long (always 32 bit, little endian byte order)

    f float (machine dependent size and representation)

    d double (machine dependent size and representation)

    x NUL byte

    X Back up one byte

    @ NUL-fill to absolute position

    Example 1. pack() format string

    $binarydata = pack ("nvc*", 0x1234, 0x5678, 65, 66);

    This information is from the downloadable PHP manual.

    ~CKM

      Hey thanks. Yea its what I was looking for its just how do I unpack it? Is there a way to take the binary and turn it back into regular text? If so and I am just missing it let me know. Thanks!
      Ziggs

        Hey nevermind I didn't see the little Unpack function. Thanks!
        Ziggs

          Write a Reply...