in , ,

How to convert Hex Color to RGB with PHP


Sometimes we need to convert HEX values of the colors in RGB values. I also faced this problem when I need to transfer HTML color picker value to PHP fpdf. There are many other use of RGB colors in various area of web designing. This problem is not big problem. There are various online tools available to convert Hex colors to RGB. If you want to create a PHP code for this, you can try the code added in the post below.


See the function hex2rgb()

This function works with both shorthand hex codes such as #f00 and longhand hex codes such as #ff0000. It also accepts the number sign (#) just in case.


You can use this function as given below

Above lines will print the rgb values of the hex passed to the function. Now you can use this function to get the RGB values of the hex.

Enjoy this coding.


Written by Deepanker

Deepanker Verma is the founder of Techlomedia. He is a tech blogger, developer and gadget freak.

Leave a Reply

Your email address will not be published. Required fields are marked *


10 WordPress Themes For Photo Gallery and Portfolio Website

Hover Image Zoom Effect With JQuery