In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "how to convert rgb to hexadecimal in php". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Php to achieve rgb to hexadecimal methods: 1, to create a PHP example file; 2, through the "function RGBToHex ($rgb) {.}" method to achieve RGB to hexadecimal can be.
This article operating environment: windows7 system, PHP7.1 version, DELL G3 computer
How does php convert rgb to hexadecimal?
The method of converting hexadecimal color to RGB color value in PHP:
Today, the editor will share with you an article about the method of converting hexadecimal color and RGB color value in PHP. The editor thinks the content is quite good. Now I will share it with you:
Hexadecimal color values are usually expressed as # FFFFFF, and some are currently reduced to # FFF, as long as the two digits must be the same, such as # FEFEFE. The color format of RGB consists of three sets of 0255digits, which represent the color values of Red, Green and Blue, respectively.
So, to convert hexadecimal to RGB color value is to convert the two bits after the # sign as a unit into decimal.
The code is as follows:
/ * convert hexadecimal colors to RGB* author www.jb51.net*/function hex2rgb ($hexColor) {$color=str_replace ('#','', $hexColor); if (strlen ($color) > 3) {$rgb=array ('ritual = > hexdec (substr ($color,0,2)),' hexdec = > hexdec ($color,2,2), 'baked = > hexdec ($color,4,2));} else {$r=substr ($color,0,1). Substr ($color,0,1); $g=substr ($color,1,1). Substr ($color,1,1); $b=substr ($color,2,1). Substr ($color,2,1); $rgb=array ('ringing = > hexdec ($r),' hexdec = > hexdec ($g), 'baked = > hexdec ($b));} return $rgb;}
Another way of writing
/ * * hexadecimal to RGB * @ param string $color hexadecimal color values * @ 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;}
RGB color and hexadecimal color conversion
/ * * RGB to hexadecimal * @ param $rgb RGB color strings such as: rgb (255255255); * @ return string hexadecimal color values such as # FFFFFF * / function RGBToHex ($rgb) {$regexp = "/ ^ rgb\ (([0-9] {0jue 3}))\,\ s * ([0-9] {0jue 3})\,\ s* ([0-9] {0pm 3})\) /" $re = preg_match ($regexp, $rgb, $match); $re = array_shift ($match); $hexColor = "#"; $hex = array ('0,'1,'2,'3,'4,'5,'6,'7,'8,'9,'A, B','C, D, E, F'); for ($I = 0; $I
< 3; $i++) { $r = null; $c = $match[$i]; $hexAr = array(); while ($c >16) {$r = $c% 16; $c = ($c / 16) > 0; array_push ($hexAr, $hex [$r]);} array_push ($hexAr, $hex [$c]); $ret = array_reverse ($hexAr); $item = implode ('', $ret); $item = str_pad ($item, 2, '0mm, STR_PAD_LEFT); $hexColor. = $item;} return $hexColor } / * hexadecimal to RGB * / function hex2rgb ($hexColor) {$color = str_replace ('#','', $hexColor); if (strlen ($color) > 3) {$rgb = array ('r' = > hexdec (substr ($color, 0,2)),'g'= > hexdec (substr ($color, 2,2)),'b' = > hexdec (substr ($color, 4,2) } else {$color = $hexColor; $r = substr ($color, 0,1). Substr ($color, 0,1); $g = substr ($color, 1,1). Substr ($color, 1,1); $b = substr ($color, 2,1). Substr ($color, 2,1); $rgb = array ('r' = > hexdec ($r),'g' = > hexdec ($g),'b' = > hexdec ($b));} return $rgb;} "how to convert rgb to hexadecimal" ends here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.