Created
July 28, 2018 14:50
-
-
Save artemsites/4ca0b9e1151a2e891dd803d971f8c8d3 to your computer and use it in GitHub Desktop.
Преобразование строки описывающей цвет из RGB формата в HEX.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Преобразует запись цвета из RGB в HEX. | |
* | |
* @param [string] $dec_color - цвет в десятичном формате 50, 100, 150; | |
* | |
* @return [string] - строка в шестнадцатиричном формате #326496; | |
*/ | |
function decToHex($dec_color) | |
{ | |
$arr_color = explode(', ', $dec_color); | |
$hex_nubmer = '#'; // будущее начало цвета в HEX формате | |
foreach ($arr_color as $dec_number) { | |
$hex_nubmer .= dechex($dec_number); | |
} | |
return $hex_nubmer; | |
} | |
// $color = decToHex('50, 100, 150'); | |
// echo "<div style='background-color: {$color}; width: 100px; height: 100px;'></div>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment