Page 1 of 1

de-coding a string

Posted: Fri Jul 20, 2007 5:06 am
by aceconcepts
Hi,

I have encoded a string in the following way:

Code: Select all

$enc_str= base64_encode(bin2hex($str));
My question is, how do I decode it so that I get the original string?

I know about base64_decode(), but this only decodes base64. What about bin2hex()?

Any suggestions?

Posted: Fri Jul 20, 2007 5:17 am
by stereofrog
to revert bin2hex use pack("H*", ...)

Posted: Fri Jul 20, 2007 5:20 am
by MalikBB
*The difficult way*

in first - base64_decode() :)
then - hexdec() - converting to normal numbers
and - decbin()

Posted: Fri Jul 20, 2007 5:49 am
by aceconcepts
Thanks everyone.

I went with Vloka's. Cheers.

Wherever it has gone!!!

Posted: Fri Jul 20, 2007 5:51 am
by volka
aceconcepts wrote: went with Vloka's..
which I deleted because it was exactly the same as stereofrog's

Posted: Fri Jul 20, 2007 7:26 am
by aceconcepts
Fair enough.