These are PHP scripts for changing background colors or text colors on your web page. Some come from BBCand from PHP.net.


With these scripts you can rotate background colors, text colors, and table colors on your web pages.

With this first script you can assign which text color will show with which background color. The colors are assigned in two separate arrays. The array number will designate which text color will go with which background color. $t1 will show on $c1 and $t2 will show on $c2, etc. You can assign as many colors as you want to each list.
$c1 = "#663300";
$c2 = "#997766";
First assign the background colors in a numbered array.
$t1 = "#997766";
$t2 = "#663300";
Next assign the text colors.
$number = rand(1,2); Next assign the number of color changes in a range from 1 to the total number in the array.
$bgcolour = ${"c$number"};< br /> $textcolour = ${"t$number"}; These codes define the variables.
To use the variables on your web page you can use either a php tag.

echo ("<body bgcolor=\"$bgcolour\">");

or within html code add the php tag inside the color tag.

<body bgcolor="<?php echo $bgcolour; ?>">

This next example assigns random colors which you have no control over, but it is an easy script and works well if you just want to change one color on your page, but it can be used for more than one item.
Put this code in the top of your page between php tags.
$hex = dechex(rand(0,255)) . dechex(rand(0,255)) . dechex(rand(0,255));
Define a new variable for each color using the same dechex codes. Then call the function with
<body bgcolor="<?php echo $hex; ?>">

This third example assigns random colors in an array,
First assign the colors you want to use.
$colours = array(
"#997766" ,
$max = count($colours); Command to count colors
$number = rand(1,$max); Command to randomize the count.
$bgcolour = $colours[$number - 1]; Variable to rotate the array ($colours).
echo "<body bgcolor=\"$bgcolour\">";

<body bgcolor="<php echo $bgcolour">">
Call the color in body tag in either php or html
$textcolor = $colours[$number - 2]; You can also change text too by adding another tag and change how it rotates.

This fourth example assigns random colors in an array and is best used for one item on your page, either background or text. First assign the colors you want to use and assign the variable for calling the random colors. Use it in your tag as in the examples above
$colours = array(
$bgcolour = $colours[array_rand($colours)]; ?>>

See Also Random GD Colors