beginning_php thread: Converting hex to ASCII
Message #1 by markpenny@e... on Wed, 29 May 2002 14:47:03|
Can anyone help with the following:
I have some hexadecimal encoded data which needs converting to ASCII. The
data is part of a MySQL field in a table. I can retrieve the data OK, but
is it possible to convert the data as it stands to ASCII using a PHP
function or two?
An example of the data is as follows: (it is the header data of an alert
logged by Snort 1.8.3. Presumably, the each pair of characters represents
a particular ASCII code. In the example, the data begins 47, 45, 54, 20
All help gratefully received!
Message #2 by markpenny@e... on Wed, 29 May 2002 18:03:23|
I've sorted this out and am posting it here in case it helps anyone else.
The command needed is pack(format code, string). It takes a bunch of
format codes and then the data to convert. There is a long list of format
codes and the ways they are used in the PHP manual.
To convert my date the command was as follows:
Where "H*" represents 'Hex string, high nibble first' and the *
represents 'parse to the end of the data'. '$row' is the data as pulled
from a MySQL query.
Hope this helps someone else!