Php RGB formate to Hex formate

If you have input as

RGB formate:rgb(xx, xx ,xx)

output formate:#xxxxxx

just use

below php method
[code language="php"]
function rgb2hex($rgb){
$str=substr($rgb,4,-1);
$colors=explode(", ",$str);
$R=$colors[0];
$G=$colors[1];
$B=$colors[2];
$R = dechex($R);
if (strlen($R)<2)
$R = '0'.$R;
$G = dechex($G);
if (strlen($G)<2)
$G = '0'.$G;
$B = dechex($B);
if (strlen($B)<2)
$B = '0'.$B;
return '#' . $R . $G . $B;
}[/code]
This method will works as you want...

Thank you keep visiting..

Comments

Post a Comment

Popular posts from this blog

Simple Mail Sending Contact Form using PHP and Jquery

Codeigniter with Admin LTE

onclick anchor tag open url in bootstrap model