hye guys, i have a .txt file which contain hex value such as F5/01/00/01/00/03/00/F5 (03 nad 01 appear as boxes in text file), and i wanted to take this value into php and convert it into binary. is it possible?

TomB
—
2013-04-08T09:57:42Z —
#2

Is the string actually the hex string? e.g."F5010001000300F5" ?

My first question, is why store it in this format? Store the binary and safe a lot of work/effort?

Marvin_G
—
2013-04-08T10:07:15Z —
#3

TomB said:

Is the string actually the hex string? e.g."F5010001000300F5" ?

My first question, is why store it in this format? Store the binary and safe a lot of work/effort?

it actually an output from a device,i just transfer it to a file.

TomB
—
2013-04-08T10:21:58Z —
#4

Have you tried:

$binary = hex2bin(file_get_contents('file.txt));

or:

$binary = pack('H*' , file_get_contents('file.txt));

Marvin_G
—
2013-04-08T14:15:04Z —
#5

TomB said:

Have you tried:

`php

$binary = hex2bin(file_get_contents('file.txt));

`

or:

`php

$binary = pack('H*' , file_get_contents('file.txt));

`

tried already..but still can't..i use this code below

$contents = file_get_contents('output.txt');
echo $contents;

and the output is õõõõõõõõõõõõ. thats F5F5F5F5F5F5F5 in ISO-8859-1 format..why is that?

TomB
—
2013-04-08T14:50:05Z —
#6

Can you paste the exact contents of output.txt or at least the first few hundred bytes.

Marvin_G
—
2013-04-08T15:10:22Z —
#7

TomB said:

Can you paste the exact contents of output.txt or at least the first few hundred bytes.