Gleasonator Posted September 8, 2008 Share Posted September 8, 2008 Hi guys. I have something a bit weird I'm doing. But here's an example of a hex string that I have. 142c2332231f00000000000000000000 Now, when this is decoded into text, the output is like so: ,#2#���������� The text that I would like to output is: Trixie To clear things up a bit, the hex string is dumped from a portion of a save file of video game. However, in the video game it renders "14" = T, "2c" = r, "23" = i... and so forth. So I would like to convert my "hex" string into a string that can be read. I know what all the values equal, but using a strreplace doesn't work (I have one "find" array, one "replace" array, and a variable containing the string then I use str_replace($find, $replace, $str);) because you get conflicts. When applying a strreplace to: 142c2332231f00000000000000000000 The output is: Tri3h3e Does anyone know of any better way I should approach this? Thanks. EDIT: In case anyone wants to look at it, here's what I have so far. I've actually not gathered all the values yet (as you can see; several chunks in the $find array only have "". But I do have enough that I should be able to convert the hex mentioned above) $find = array( "00", "", "", "", "", "", "3a", "3b", "3c", "3d", "3e", "01", "1b", "02", "1c", "03", "1d", "04", "1e", "05", "1f", "06", "20", "07", "21", "08", "22", "09", "23", "0a", "24", "0b", "25", "0c", "26", "0d", "27", "0e", "28", "0f", "29", "10", "2a", "11", "2b", "12", "2c", "13", "2d", "14", "2e", "15", "2f", "16", "", "17", "", "18", "32", "19", "33", "1a", "34", ); $replace = array( "", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "a", "B", "b", "C", "c", "D", "d", "E", "e", "F", "f", "G", "g", "H", "h", "I", "i", "J", "j", "K", "k", "L", "l", "M", "m", "N", "n", "O", "o", "P", "p", "Q", "q", "R", "r", "S", "s", "T", "t", "U", "u", "V", "v", "W", "w", "X", "x", "Y", "y", "Z", "z", ); $output = str_replace($find, $replace, $str); Link to comment https://forums.phpfreaks.com/topic/123189-solved-converting-hex-into-different-ascii-characters/ Share on other sites More sharing options...
Gleasonator Posted September 8, 2008 Author Share Posted September 8, 2008 Ah, never mind, guys. I got it myself. function get_pattern_name($filename) { $open = fopen($filename, "r"); $read = fread($open, filesize($filename)); $str = substr(bin2hex($read), 1068, 32); $arr = str_split($str, 2); $find = array( "00", "", "", "", "", "", "3a", "3b", "3c", "3d", "3e", "01", "1b", "02", "1c", "03", "1d", "04", "1e", "05", "1f", "06", "20", "07", "21", "08", "22", "09", "23", "0a", "24", "0b", "25", "0c", "26", "0d", "27", "0e", "28", "0f", "29", "10", "2a", "11", "2b", "12", "2c", "13", "2d", "14", "2e", "15", "2f", "16", "", "17", "", "18", "32", "19", "33", "1a", "34", ); $replace = array( "", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "a", "B", "b", "C", "c", "D", "d", "E", "e", "F", "f", "G", "g", "H", "h", "I", "i", "J", "j", "K", "k", "L", "l", "M", "m", "N", "n", "O", "o", "P", "p", "Q", "q", "R", "r", "S", "s", "T", "t", "U", "u", "V", "v", "W", "w", "X", "x", "Y", "y", "Z", "z", ); $output = implode(str_replace($find, $replace, $arr)); return $output; } Link to comment https://forums.phpfreaks.com/topic/123189-solved-converting-hex-into-different-ascii-characters/#findComment-636236 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.