• Advertisement
Sign in to follow this  

[web] unpack: Binary string to hex string (PHP)

This topic is 4444 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to use the unpack function in PHP to convert a text or binary string to its hexadecimal representation (e.g. 'hello' -> '68656c6c6f')
function _hexstring($bin)
{
	list(,$ret) = unpack('h1', $bin);
	return($ret);
}
I'm missing something fundamental here. It returns a blank string. Anybody have an idea? ~BenDilts( void );

Share this post


Link to post
Share on other sites
Advertisement
Try:


function _hexstring($bin)
{
list(,$ret) = unpack('H'.strlen($bin)*2, $bin);
return($ret);
}

Share this post


Link to post
Share on other sites

function _hexstring($bin)
{
list(,$ret) = unpack('h*1', $bin);
return($ret);
}

Solved.

Thanks, you pointed me in the right direction!



~BenDilts( void );

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement