Connecting Tech Pros Worldwide Forums | Help | Site Map

Reading hexdump text file

Newbie
 
Join Date: May 2007
Posts: 5
#1: Jul 8 '08
Hey guys, here is something interesting. Let say you want to read the below hexdump.txt into a Array() the way it appears on the screen. But for some reason, php keep removing the extra spaces.

So the first line will be read as:
[HTML]78 29 0D 0A 20 20 7B 0D 0A 20 20 20 20 24 73 74 // x).. {.. $st
[/HTML]

Instead of (which is what I want):
[HTML]78 29 0D 0A 20 20 7B 0D 0A 20 20 20 20 24 73 74 // x).. {.. $st[/HTML]

hexdump.txt:
[HTML]78 29 0D 0A 20 20 7B 0D 0A 20 20 20 20 24 73 74 // x).. {.. $st
72 69 6E 67 20 3D 20 4E 55 4C 4C 3B 0D 0A 20 20 // ring = NULL;..
20 20 24 68 65 78 20 3D 20 73 74 72 5F 72 65 70 // $hex = str_rep
6C 61 63 65 28 61 72 72 61 79 28 22 5C 6E 22 2C // lace(array("\n",
22 5C 72 22 29 2C 20 22 22 2C 20 24 68 65 78 29 // "\r"), "", $hex) [/HTML]

Any idea how I can read the text file just the way it is?
Thanks!

Newbie
 
Join Date: May 2007
Posts: 5
#2: Jul 8 '08

re: Reading hexdump text file


I think I figured out, this is for anyone who have the similar problem.

As we all know, HTML treats multiple consecutive "non-breaking space' as one single space. That's why it appears as if php trim the strings.

Two way to get it to show up:
1. enclose the the String in a <pre> tag
2. replace ' ' with '&nbsp;'
for example: str_replace(' ', '&nbsp;', htmlspecialchars($string))
Reply


Similar PHP bytes