/ Published in: PHP

Any comments/suggestions are always welcome.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php /** * Inverses a provided hex color. If you pass a hex string with a * hash(#), the function will return a string with a hash prepended * * @param string $color Hex color to flip. * A 3 or 6 character hex code, with or without a leading '#'. * * @return string Reversed hex color * @author Koncept * * Last Update: 2020-03-04 */ function inverse_hex(string $color):string { $prependHash = FALSE; $prependHash = TRUE; } case 3: /** @var string $color */ break; case 6: // Already acceptable, passthrough break; default: trigger_error("Invalid hex length ($len). Must be a minimum length of (3) or maxium of (6) characters", E_USER_ERROR); } throw new RuntimeException(sprintf('Invalid hex string #%s', htmlspecialchars($color, ENT_QUOTES))); } return ($prependHash ? '#' : NULL) . $r . $g . $b; } // Demo echo inverse_hex('#000'); // #ffffff
Comments
