views:

1278

answers:

1

I'm investigating encodings in PHP5. Is there some way to get a raw hex dump of a string? i.e. a hex representation of each of the bytes (not characters) in a string?

+3  A: 
for ($i = 0; $i < strlen($string); $i++) {
    echo dechex(ord($string[$i]));
}

or easier

echo bin2hex($string);
Stefan Gehrig
Or a more functional approach:print_r(array_map('dechex', array_map('ord', str_split($string))));
Ionuț G. Stan