PHP functions convert 16 color codes to RGB color values _php Tutorial

Source: Internet
Author: User
Tags string to json

PHP functions convert 16 color codes to RGB color values


Use the PHP function to convert 16 forbidden color codes to RGB color values.

/** * Function 16 binary color converted 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, =SUBSTR); $b ($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 PHP converts BR newline characters in HTML to line breaks in text input
    • PHP converts consecutive spaces in a string to a space
    • PHP converts full-width characters in a string to half-width characters
    • JS How to convert the returned string to JSON-formatted data
    • PHP uses the Session_set_save_handler () function to save the session to the MySQL database
    • How PHP converts an IP address to a real address
    • PHP using ziparchive function to realize the compression and decompression of files
    • PHP implementation restricts domain names and protects source code from being copied

http://www.bkjia.com/PHPjc/1000763.html www.bkjia.com true http://www.bkjia.com/PHPjc/1000763.html techarticle The PHP function converts a 16-color code into an RGB color value using a PHP function to convert a 16 forbidden color code to an RGB color value. /** * Function 16 binary color converted to RGB color value * Author www.php ...

  • Related Article

    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.