Jump to content

Converting RGB values to HEX


johnsliced

Recommended Posts

<?PHP

$file_handle = fopen("colors/rgb.csv", "r");

while (!feof($file_handle) ) {

$line_of_text = fgetcsv($file_handle, 1024);

print $line_of_text[2] . $line_of_text[3] . $line_of_text[4] . "<BR>";

}

fclose($file_handle);

?>

 

my code above currently outputs a list of RGB numbers for example:

 

Ref_RRef_GRef_B

149119109

190171158

200161148

154109111

1088888

1408579

 

I would like to now convert these numbers (each line) to HEX colors

 

please help?!

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/177669-converting-rgb-values-to-hex/
Share on other sites

Split it up and use dechex.

 

By the way, you've chosen a really bad format for storing it in. Take for instance this: 11211222. It could be either 11,211,222 or 112,11,222 or 112,112,22.

 

Edit: Ah, never mind. I didn't notice that it was just the way you were outputting it. In that case, just call dechex() on all of them.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.