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?
While debugging a binary protocol I needed a hexdump() too. I decided to publish my solution as a PEAR package as it's definitely useful. You can also browse the code at github.
PEAR : http://www.metashock.de/pear
GitHub : http://www.github.com/metashock/Hexdump
In addition to mindplays solution it supports propper rendering of the last line and additional params. Also the package contains a php executable named phphd for hexdumps on cmdline. This might be helpful on Windows Systems :)
@mindplay.dk : Thanks for the strtr() idea. It appeared slight faster than my former attempt. Integrated that into my version. (Using a decreased translation buffer)..
Have Fun!