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

  • Home
  • SEARCH
  • 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 916093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:59:37+00:00 2026-05-15T17:59:37+00:00

How would I generate a color based on what letter a string begins with

  • 0

How would I generate a color based on what letter a string begins with – perhaps A could be blue, Z could be green and the other letters would be the gradually changing spectrum in between?

  • 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-05-15T17:59:37+00:00Added an answer on May 15, 2026 at 5:59 pm

    Try this function:

    Generate Gradient Within Hex Range In PHP

    A function that generates an array of hex colors that forms a
    gradient, starting from a hex color and ending with another hex color.
    The number of gradient steps can also be defined.

    function Gradient($HexFrom, $HexTo, $ColorSteps)
    {
            $FromRGB['r'] = hexdec(substr($HexFrom, 0, 2));
            $FromRGB['g'] = hexdec(substr($HexFrom, 2, 2));
            $FromRGB['b'] = hexdec(substr($HexFrom, 4, 2));
           
            $ToRGB['r'] = hexdec(substr($HexTo, 0, 2));
            $ToRGB['g'] = hexdec(substr($HexTo, 2, 2));
            $ToRGB['b'] = hexdec(substr($HexTo, 4, 2));
           
            $StepRGB['r'] = ($FromRGB['r'] - $ToRGB['r']) / ($ColorSteps - 1);
            $StepRGB['g'] = ($FromRGB['g'] - $ToRGB['g']) / ($ColorSteps - 1);
            $StepRGB['b'] = ($FromRGB['b'] - $ToRGB['b']) / ($ColorSteps - 1);
           
            $GradientColors = array();
           
            for($i = 0; $i <= $ColorSteps; $i++)
            {
                    $RGB['r'] = floor($FromRGB['r'] - ($StepRGB['r'] * $i));
                    $RGB['g'] = floor($FromRGB['g'] - ($StepRGB['g'] * $i));
                    $RGB['b'] = floor($FromRGB['b'] - ($StepRGB['b'] * $i));
                   
                    $HexRGB['r'] = sprintf('%02x', ($RGB['r']));
                    $HexRGB['g'] = sprintf('%02x', ($RGB['g']));
                    $HexRGB['b'] = sprintf('%02x', ($RGB['b']));
                   
                    $GradientColors[] = implode(NULL, $HexRGB);
            }
            return $GradientColors;
    }
     
    $Gradients = Gradient("FF5B5B", "FFCA5B", 32);
    foreach($Gradients as $Gradient)
    {
            echo "<div style=\"background-color: #".$Gradient."; width: 100px; height: 25px;\"></div>";
    }
    

    From https://web.archive.org/web/20160915121028/http://www.geekpedia.com/code163_Generate-Gradient-Within-Hex-Range-In-PHP.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write some LINQ To SQL code that would generate SQL like
How would you generate an JPG image file containing data fields that are stored
I'm in a situation where I would to generate a script for a database
I would like to generate a random floating point number between 2 values. What
I would like to generate a WSDL file from a c++ atl webservice without
I would like to generate a list of files within a directory. Some of
I have a project where I would like to generate a report export in
Learning a little about T-SQL, and thought an interesting exercise would be to generate
I would like to force svcutil to generate all data contracts in an assembly
What I would like is be able to generate a simple report that is

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.