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 8222329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:14:34+00:00 2026-06-07T14:14:34+00:00

I realize that there have already been several threads on this type of question,

  • 0

I realize that there have already been several threads on this type of question, but none that seemed to match mine. I have code that is correctly displaying a series of 6 numbers for a CSS background. Those 6 numbers are then stored into an array and the contents of that array are concatenated with a “#” sign in front of it. That, then is stored as another variable. Here:

$v = 0;
$array = array();
$tot;
$other0 = null;
$other1 = null;
$other2 = null;
$other3 = null;
$other4 = null;
$other5 = null;
$color;

for ($i=0;$i<6;$i++){ //loops 6 times to create 5 numbers
    $tot = rand(0, 15);

    if (($tot>9) && ($tot<16)){ //assigns 10 to "a" in hex
        if ($tot == 10){
            $tot = $other0;
            $other0 = "a";
            //echo $other0;
            $array[$v++] = $other0;
        }
        elseif ($tot == 11){ //assigns 11 to "b" in hex
            $tot = $other1;
            $other1 = "b";
            //echo $other1;
            $array[$v++] = $other1;
        }
        elseif ($tot == 12){ //assigns 12 to "b" in hex
            $tot = $other2;
            $other2 = "c";
            //echo $other2;
            $array[$v++] = $other2;
        }
        elseif ($tot == 13){ //assigns 13 to "b" in hex
            $tot = $other3;
            $other3 = "d";
            //echo $other3;
            $array[$v++] = $other3;
        }
        elseif ($tot == 14){ //assigns 14 to "b" in hex
            $tot = $other4;
            $other4 = "e";
            //echo $other4;
            $array[$v++] = $other4;
        }
        elseif ($tot == 15) { //assigns 15 to "b" in hex
            $tot = $other5;
            $other5 = "f";
            //echo $other5;
            $array[$v++] = $other5;
        }

    }
    else {
        //echo $tot;
        $array[$v++] = $tot; //if not, then just assign to array
    }
}
$var = "";
$color = "";
for ($t=0; $t<6;$t++){
    $var .= (string) $array[$t]; //displays the 6 numbers as one string
}
//var_dump($var); //for more visual reference, uncomment the var_dump
$color = "#" . $var;
echo $color;

That above is in PHP.

How do I get that variable to be displayed using CSS? Is it like (in the same PHP file): echo "<style>color:$color</style>";

or do I have to make a style.php for it to be referenced? If I do, how do I do that?

Many thanks!

  • 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-07T14:14:37+00:00Added an answer on June 7, 2026 at 2:14 pm

    Well it looks like "<style>color:$color</style>"; will output broken html/css.

    Try amending

    echo '<style type="text/css"> body { background: '.$color.' } </style>';
    

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

Sidebar

Related Questions

I realize there's already been several questions like this, but I think my case
I realize that there have been similar questions, but they seem to have been
I realize that this question has been answered before, and I have looked through
I realize that there are many threads already posted that deal with this very
I realize that a SO user has formerly asked this question but it was
I realize there have been a few other questions on this topic, and the
I realize there have already been a number of posts on n-tier design and
I realize that there are many similar questions, but most involve scaling down the
I realize that the answer to this question is likely quite obvious (if somewhat
I apologize if this has already been asked a different way but I couldn't

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.