Home >Backend Development >PHP Problem >How to convert php hexadecimal color to rgb
php How to convert hexadecimal color to rgb: First create a PHP sample file; then use the "public static function hex2rgb($color){...}" method to convert hexadecimal color to RGB color Just value.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
PHP hexadecimal color to RGB color value
/** * 十六进制转RGB * * @param string $color 16进制颜色值 * @return array */ public static function hex2rgb($color) { $hexColor = str_replace('#', '', $color); $lens = strlen($hexColor); if ($lens != 3 && $lens != 6) { return false; } $newcolor = ''; if ($lens == 3) { for ($i = 0; $i < $lens; $i++) { $newcolor .= $hexColor[$i] . $hexColor[$i]; } } else { $newcolor = $hexColor; } $hex = str_split($newcolor, 2); $rgb = []; foreach ($hex as $key => $vls) { $rgb[] = hexdec($vls); } return $rgb; }
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to convert php hexadecimal color to rgb. For more information, please follow other related articles on the PHP Chinese website!