How to convert Hex Color to RGB with PHP

Best WordPress Hosting

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.

Demo

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.

advertisement

About The Author

  • ADD YOUR COMMENT

Subscribe To Our Newsletter

Subscribe To Our Newsletter

Receive fresh web design resources and SEO tips in your email by our weekly newsletter

You have Successfully Subscribed!