SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2000
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi everyone,

    Does anybody know, or have the code (in PHP) for converting HTML color code into rgb, and return it as an array for Red, Green, and Blue ?

    any help would be appreciated.

    Thank you
    Sang N.
    -------------------------------
    Send an E-card today!
    http://ecard.vinasite.com

  2. #2
    SitePoint Zealot oodie's Avatar
    Join Date
    Jul 2000
    Location
    Misty Mountain
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just made this :

    <?php
    function hex2rgb($color) {

    if(strlen($color) != 6) {
    echo "Not a valid hex color";
    return 0;
    }

    for($i=0; $i<3; $i++) {
    $hex = substr($color,2*$i,2);
    $rgb[$i] = 16 * hexdec(substr($hex,0,1)) + hexdec(substr($hex,1,1));
    }

    return $rgb;
    }
    ?>

    Example :
    <?php
    $hex_color = "003366";
    $rgb_color = hex2rgb($hex_color);

    echo "Red = $rgb_color[0]";
    echo "Green = $rgb_color[1]";
    echo "Blue = $rgb_color[2]";
    ?>

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2000
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you!!!

    :-)
    Sang N.
    -------------------------------
    Send an E-card today!
    http://ecard.vinasite.com


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •