Last active
March 20, 2021 00:56
-
-
Save admcfajn/6f5b2003d9610047e91c8cc8a3354310 to your computer and use it in GitHub Desktop.
RGB HEX #FF0000 to RGB 255 ( 255, 0, 0 ) in PHP
This file contains hidden or 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
| <?php | |
| /** | |
| * Convert RGB HEX to RGB 255 in PHP | |
| */ | |
| function hex_to_rgb ( $color_code ) { | |
| $hex_string = str_replace( '#', '', $color_code ); | |
| $hex = [ | |
| 'r' => substr( $hex_string, 0, 2 ), | |
| 'g' => substr( $hex_string, 2, 2 ), | |
| 'b' => substr( $hex_string, 4, 2 ) | |
| ]; | |
| $rgb = [ | |
| hexdec( $hex['r'] ), | |
| hexdec( $hex['g'] ), | |
| hexdec( $hex['b'] ) | |
| ]; | |
| $rgb_string = implode( ', ', $rgb ); | |
| return $rgb_string; | |
| } | |
| echo hex_to_rgb( '#ff0000' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment