I'd like to represent strings as arbitrary html colors.
Example:
"blah blah" = #FFCC00
"foo foo 2" = #565656
It doesn't matter what the actual color code is, so long as it's a valid hexadecimal HTML color code and the whole spectrum is fairly well represented.
I guess the first step would be to do an MD5 on the string and then somehow convert that to hexadecimal color code?
Update: Usage example is to generate a visual report of file requests on a server. The colors don't have to look pretty, it's more so a human brain can detect patterns, etc in the data more readily.
HEX Color Values For example, #ff0000 is displayed as red, because red is set to its highest value (ff), and the other two (green and blue) are set to 00. Another example, #00ff00 is displayed as green, because green is set to its highest value (ff), and the other two (red and blue) are set to 00.
Learn HTML You can specify colors on page level using <body> tag or you can set colors for individual tags using bgcolor attribute. bgcolor − sets a color for the background of the page. text − sets a color for the body text. alink − sets a color for active links or selected links.
Thanks for the pointers, this seems to do a competent job:
function stringToColorCode($str) { $code = dechex(crc32($str)); $code = substr($code, 0, 6); return $code; } $str = 'test123'; print '<span style="background-color:#'.stringToColorCode($str).'">'.$str.'</span>';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With