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

Started by
1 comment, last by BeanDog 18 years, 5 months ago
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 );
Advertisement
Try:

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

Solved.

Thanks, you pointed me in the right direction!



~BenDilts( void );

This topic is closed to new replies.

Advertisement