PHP implements the method of converting the color hex value to RGB

Source: Internet
Author: User
Tags getting started with php php programming
The example in this paper describes the method of converting the color hex value to RGB by PHP. Share to everyone for your reference, as follows:

function Hex2rgb ($colour) {     if ($colour [0] = = ' # ') {         $colour = substr ($colour, 1);     }     if (strlen ($colour) = = 6) {         list ($r, $g, $b) = Array ($colour [0]. $colour [1], $colour [2]. $colour [3], $colour [ 4]. $colour [5]);     } ElseIf (strlen ($colour) = = 3) {         list ($r, $g, $b) = Array ($colour [0]. $colour [0], $colour [1]. $colour [1], $col OUR[2]. $colour [2]);     } else {         return false;     }     $r = Hexdec ($r);     $g = Hexdec ($g);     $b = Hexdec ($b);     Return array (' red ' = $r, ' green ' = $g, ' blue ' = $b); }//Test Var_dump (Hex2rgb ("#eeeeee"));

The results of the operation are as follows:

Array (3) {["Red"]=> Int (238) ["Green"]=> Int (238) ["Blue"]=> int (238)}

For color value conversion and acquisition can also refer to the site online tools:

RGB Color Coding Generator

Online Web color Matching tool

RGB Color Query Chart _ color code table _ color of the English name Daquan

More readers interested in PHP related content can view the topic: "PHP array" operation Skills Daquan, "PHP Math Skills Summary", "PHP graphics and pictures Operation Skills Summary", "PHP operation Office Document tips summary (including Word,excel, access,ppt), "PHP Date and Time usage summary", "PHP primer for Object-oriented programming", "PHP String Usage Summary", "Getting Started with Php+mysql database operations" and "PHP Common Database Operations Skills Summary"

I hope this article is helpful to you in PHP programming.

The above describes the implementation of PHP to convert the color hex value to RGB, including the content, I hope that the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.