Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8468425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:55:43+00:00 2026-06-10T15:55:43+00:00

I am working on a dynamic store project and I use a loop to

  • 0

I am working on a dynamic store project and I use a loop to print all color options for a product as color boxes, however I really need to add a “border” to these colors which are light. I tried something like the following but It is very limited, it is actually limited to white color only, it won’t catch something like #ddd, #eea… etc

Here is my loop:

foreach($colors as $color) {
    $color = trim($color);
    if (!empty($color)) {
        if (in_array($color, array('white','White','#fff','#FFF','#FFFFFF','#ffffff'))) {
            $bordercolor = '#bbb';
        } else {
            $bordercolor = $color;
        }
    }
}

Colors is an array from backend like: White, #000, #cc0000, etc. It is not practical to add all exceptions in the if/else condition too, any quick idea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:55:44+00:00Added an answer on June 10, 2026 at 3:55 pm

    Transform HTML colour to RGB, then to Hue-Saturation-Lightnes (HSV)

    <?php
    
    function HTMLToRGB($htmlCode)
      {
        if($htmlCode[0] == '#')
          $htmlCode = substr($htmlCode, 1);
    
        if (strlen($htmlCode) == 3)
        {
          $htmlCode = $htmlCode[0] . $htmlCode[0] . $htmlCode[1] . $htmlCode[1] . $htmlCode[2] . $htmlCode[2];
        }
    
        $r = hexdec($htmlCode[0] . $htmlCode[1]);
        $g = hexdec($htmlCode[2] . $htmlCode[3]);
        $b = hexdec($htmlCode[4] . $htmlCode[5]);
    
        return $b + ($g << 0x8) + ($r << 0x10);
      }
    
    function RGBToHSL($RGB) {
        $r = 0xFF & ($RGB >> 0x10);
        $g = 0xFF & ($RGB >> 0x8);
        $b = 0xFF & $RGB;
    
        $r = ((float)$r) / 255.0;
        $g = ((float)$g) / 255.0;
        $b = ((float)$b) / 255.0;
    
        $maxC = max($r, $g, $b);
        $minC = min($r, $g, $b);
    
        $l = ($maxC + $minC) / 2.0;
    
        if($maxC == $minC)
        {
          $s = 0;
          $h = 0;
        }
        else
        {
          if($l < .5)
          {
            $s = ($maxC - $minC) / ($maxC + $minC);
          }
          else
          {
            $s = ($maxC - $minC) / (2.0 - $maxC - $minC);
          }
          if($r == $maxC)
            $h = ($g - $b) / ($maxC - $minC);
          if($g == $maxC)
            $h = 2.0 + ($b - $r) / ($maxC - $minC);
          if($b == $maxC)
            $h = 4.0 + ($r - $g) / ($maxC - $minC);
    
          $h = $h / 6.0; 
        }
    
        $h = (int)round(255.0 * $h);
        $s = (int)round(255.0 * $s);
        $l = (int)round(255.0 * $l);
    
        return (object) Array('hue' => $h, 'saturation' => $s, 'lightness' => $l);
      }
    
    $colour = '#F12346';
    $rgb = HTMLToRGB($colour);
    $hsl = RGBToHSL($rgb);
    
    var_dump($hsl);
    

    Usage:

    $colour = '#F12346';
    $rgb = HTMLToRGB($colour);
    $hsl = RGBToHSL($rgb);
    if($hsl->lightness > 200) {
      // this is light colour!
    }
    

    Source:

    • http://www.caperna.org/computing/repository/hsl-rgb-color-conversion-php

    Demo:

    • http://codepad.org/X7KV4n4n
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're working in a Dynamic Data project that will handle entities coming from two
I am working on a dynamic report where charts need to be recreated on
I'm currently working on a project where I need to save data depending upon
For a project I'm working I need to have some sort of enumaration class
I have a Crystal Reports project that I am working on where I need
Hello Im working on a django project where i want to store a set
I'm working on a site where we need dynamic breadcrumb generation. Pages within this
I'm working on an academic open source project and now I need to create
I'm working on an AIR application which generates a dynamic client presentation, pulling all
I need to create a dynamic Excel formula through a Perl script. I store

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.