Php's method of converting colors into their reversed colors
This article mainly introduces how to convert the color of php into the reversed color. It involves related techniques related to the color numeric operations in php. For more information, see
This article describes how to convert the color of php to its reversed color. Share it with you for your reference. The specific analysis is as follows:
This php code converts a color to the opposite color encoding, for example, white to black, and blue to yellow.
?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
Function color_inverse ($ color ){ $ Color = str_replace ('#', '', $ color ); If (strlen ($ color )! = 6) {return '000000 ';} $ Rgb = ''; For ($ x = 0; $ x <3; $ x ++ ){ $ C = 255-hexdec (substr ($ color, (2 * $ x), 2 )); $ C = ($ c <0 )? 0: dechex ($ c ); $ Rgb. = (strlen ($ c) <2 )? '0'. $ c: $ c; } Return '#'. $ rgb; } // Example: // Black-> white Print color_inverse ('#000000 '); // --> Returns # ffffff // Blue-> yellow Print color_inverse ('# 0000FF '); // --> # FFFF00 |
I hope this article will help you with php programming.