Programming Forum
September 08, 2010, 07:26:28 PM
Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News
:
Home
Help
Search
Login
Register
Programming Forum
>
General Category
>
General Discussion
>
Color
Pages: [
1
]
« previous
next »
Print
Author
Topic: Color (Read 705 times)
Brady
Newbie
Posts: 1
Color
«
on:
June 07, 2008, 05:11:28 PM »
How do you make a background page color change randomly in PHP?
Logged
Mark
Administrator
Newbie
Posts: 0
Re: Color
«
Reply #1 on:
June 07, 2008, 05:18:26 PM »
Here is one way you can randomly change the background color in PHP.
[code]
<?php
print "<html>\n";
$intRed = rand(0,255); // generates a random number between 0 and 255
$intGreen = rand(0,255);
$intBlue = rand(0,255);
$hexRed = dechex($intRed+0); // converts the number to hex
$hexGreen = dechex($intGreen+0);
$hexBlue = dechex($intBlue+0);
$strRed=$hexRed;
// makes the value two characters wide so red, green, and blue each take two characters in the RGB value
if (strlen($strRed) == 1) { $strRed="0".$strRed; }
$strGreen=$hexGreen;
if (strlen($strGreen) == 1) { $strGreen="0".$strGreen; }
$strBlue=$hexBlue;
if (strlen($strBlue) == 1) { $strBlue="0".$strBlue; }
$hexRGB=$strRed.$strGreen.$strBlue; // joins the three string vales to make a RGB value
print "<body bgcolor=$hexRGB>\n";
print "The background page color is $hexRGB\n";
print "</body>\n";
print "</html>\n";
?>
[/code]
«
Last Edit: July 09, 2010, 10:50:02 PM by Mark
»
Logged
Pages: [
1
]
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
General Category
-----------------------------
=> General Discussion
Entrylevelprogrammer.com Home Page
Loading...