RsD0p9BK
12/12/2016 - 10:19 AM

php__rgb2hex.php

// Convert RGB Color to Hex using PHP

function rgb2hex($rgb) {
  $hex = "#";
  $hex .= str_pad(dechex($rgb[0]), 2, "0", STR_PAD_LEFT);
  $hex .= str_pad(dechex($rgb[1]), 2, "0", STR_PAD_LEFT);
  $hex .= str_pad(dechex($rgb[2]), 2, "0", STR_PAD_LEFT);
  
  return $hex; // returns the hex value including the number sign (#)
}

// https://bavotasan.com/2011/convert-hex-color-to-rgb-using-php/