de-coding a string

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

de-coding a string

Post 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?
User avatar
stereofrog
Forum Contributor
Posts: 386
Joined: Mon Dec 04, 2006 6:10 am

Post by stereofrog »

to revert bin2hex use pack("H*", ...)
MalikBB
Forum Newbie
Posts: 11
Joined: Fri Jul 20, 2007 4:34 am
Contact:

Post by MalikBB »

*The difficult way*

in first - base64_decode() :)
then - hexdec() - converting to normal numbers
and - decbin()
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

Thanks everyone.

I went with Vloka's. Cheers.

Wherever it has gone!!!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

aceconcepts wrote: went with Vloka's..
which I deleted because it was exactly the same as stereofrog's
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

Fair enough.
Post Reply