<?phpnamespaceMayMeow\PHPColor;classColor{/** int $red */public$red;/** int $green */public$green;/** int $blue */public$blue;publicfunction__construct($red,$green,$blue){$this->red=$red;$this->green=$green;$this->blue=$blue;}/**
* Method convertToHex
* Covert given color to string #RRGGBB
*/publicstaticfunctionconvertToHex(Color$color){$red=dechex($color->red);if(strlen($red)<2)$red='0'.$red;// check string length and add zero if needed$green=dechex($color->green);if(strlen($green)<2)$green='0'.$green;$blue=dechex($color->blue);if(strlen($blue)<2)$blue='0'.$blue;return'#'.$red.$green.$blue;}/**
* Method convertToRGB
* Convert given color string back to RGB color values
*/publicstaticfunctionconvertToRGB($hex){$hex=ltrim($hex,"#");$red=hexdec(substr($hex,0,2));$green=hexdec(substr($hex,2,2));$blue=hexdec(substr($hex,4,2));returnnewColor($red,$green,$blue);}}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
My solution in PHP