Page 1 of 1
outputting a hex file
Posted: Sun Nov 26, 2006 1:37 pm
by bdean
Hi I wonder if anyone can help me. I have a MySQL table that contains a series of hex colour codes and I need to output them to a file. This I can do ok but I need the file to be in a hex format so that when a hex editor opens it reads it correctly. At the moment all I seem to do is create it as a text file then when the hex editor opens it doesn't read it correctly. I hope I've explained myself correctly. The file will be a .act file which will be fed into Photoshop
Any help much appreciated.
Posted: Sun Nov 26, 2006 8:54 pm
by feyd
You mean you want the hex codes translated to their binary forms so the hex editor sees the original hex codes?
dechex().
Posted: Mon Nov 27, 2006 2:17 am
by bdean
Thanks for the reply. No, it's not that. I have the hex values but when I output the file the hex editor doesn't think it's a hex file just a text file so I must need to do something with the format of the file or how I output but for the life of me can't work it out.
Posted: Mon Nov 27, 2006 5:53 am
by TheProgrammer
Can't give an estimate on how will work but try getting each hex number (if you have it saved as string, then every letter) and then convert the hex value to decimal, then convert it to the specific character with that code using chr.
Probably like this:
Code: Select all
//do this for each hex number -> for a color do it 6 times
$outputString .= chr( hexdec( $letter ) )
take care there: hexdec takes a string as paramete
Hope it helps. If it does please let me know, I realy am interested if it works. I will probably need this once, but don't have the time to test it now.

Posted: Mon Nov 27, 2006 7:04 am
by bdean
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi
Thanks for that - what I actually had to do was split the hex colour code into the 3 parts - then run the function on that and works great:
Code: Select all
$hex=$row['hexcode'];
$r1= substr($hex,0,2);
$g1= substr($hex,2,2);
$b1=substr($hex,4,2);
$outputString="";
$outputString .= chr( hexdec( $r1 ) ) ;
$outputString .= chr( hexdec( $g1 ) ) ;
$outputString .= chr( hexdec( $b1 ) ) ;
Thanks for your help.
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Mon Nov 27, 2006 1:52 pm
by feyd
pack() may be of interest.