You can try this simple piece of code below. You can also pass rgb code dynamically and in code.
$rgb = (123,222,132); $rgbarr = explode(",",$rgb,3); echo sprintf("#%02x%02x%02x", $rgbarr[0], $rgbarr[1], $rgbarr[2]);
This will return a code like # 7bde84
source share