Php function to convert hexadecimal color code to RGB color value _ PHP Tutorial

Source: Internet
Author: User
Tags string to json
The php function converts the hexadecimal color code to an RGB color value. The php function converts the hexadecimal color code to the RGB color value. The php function is used to convert the 16 forbidden color code to the RGB color value. * ** Convert the base-16 color to an RGB color value * the authorwww. php function converts the base-16 color code to an RGB color value.

Use the php function to convert the 16 forbidden color code to an RGB color value.

/*** Function hexadecimal color conversion to RGB color value * author www.phpernote.com */function hex2rgb ($ hexColor) {$ color = str_replace ('#','', $ hexColor); if (strlen ($ color)> 3) {$ rgb = array ('R' => hexdec (substr ($ color, 0, 2 )), 'G' => hexdec (substr ($ color, 2, 2), 'B' => hexdec (substr ($ color, 4, 2 )));} else {$ color = str_replace ('#', '', $ hexColor); $ r = substr ($ color, 0, 1 ). substr ($ color, 0, 1); $ g = substr ($ color, 1, 1 ). substr ($ color, 1, 1); $ B = substr ($ color, 2, 1 ). substr ($ color, 2, 1); $ rgb = array ('R' => hexdec ($ r), 'G' => hexdec ($ g ), 'B' => hexdec ($ B);} return $ rgb ;}

For example:

Print_r (hex2rgb ('# F03'); // output: Array ([r] => 255 [g] => 0 [B] => 51)
Articles you may be interested in
  • How does php convert the br line breaks in html to line breaks in text input?
  • Php converts multiple consecutive spaces in a string into one.
  • Php converts all-round characters in a string to half-width characters.
  • How does js convert the returned string to json format data?
  • Php uses the session_set_save_handler () function to save the session to the MySQL database.
  • Php to convert an IP address to a real address
  • Php uses the ZipArchive function to compress and decompress files.
  • PHP restricts domain names to protect source code from being copied

The http://www.bkjia.com/PHPjc/1000763.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1000763.htmlTechArticlephp function converts the hexadecimal color code to the RGB color value using the php function to convert the 16 forbidden color code to the RGB color value. /*** Function hexadecimal color conversion to RGB color value * author www. php...

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.