Swobodin's website
 
Index Articles Downloads Contact Guestbook Links
Chess Curiosities
Linux Tricks
PHP Scripts

UNIX is many things to
many people, but it's
never been everything to
anybody.

Programming time

What's is your favorite time to program?

Morning
Afternoon
Evening
Night
Any time, depends on my character
I don't program

View poll results



Welcome, dear visiotor, and greetings to Spain Spain
(According to your IP: 107.20.129.212)

UP
Home

PHP Color Chart

Rate the article

Comment the article

This script was totally inspired form a JavaScript program written by < href="http://members.xoom.com/yoboseyo" target=_blank>Dion ; I have "translated" it to PHP and added some modifications. The puropse is generating a color chart containing 4096 colors with hexadecimal values in a few lines.

<?php 

 $color
=Array('00','20','30','40','50','60','70','80','90','A0','B0','C0','D0','E0','F0','FF');

//declares variable "color", corresponding with the 16 values above, I think they are the most useful

for ($R=0;$R<16;$R++) {

//function for : the variable "R" (Red) is between 0 and 16

echo('<center><table style "border-width: 3; border-color: #FFFFFF ; border-style: ridge" width =""50%"">');

//drawing a table

for ($G=0;$G<16;$G++) {

//function for : the variable "G" (Green) is between 0 and 16

echo("<tr>");

for (
$B=0;$B<16;$B++) {

//function for : the variable "B" (Blue) is between 0 and 16

echo('<td bgcolor="#'.$color[$R].$color[$G].$color[$B].'">');

//all values of R, G and B will be crossed and applied as background

echo('<p style"color:#'.$color[15-$B].$color[15-$G].$color[15-$R].'; font-family: Verdana ; font-size: 10;"'); // just to make the color of written values different from the applied one 

echo($color[$R].$color[$G].$color[$B].' </p></td>'); } //writing the hexadecimal values

echo('</tr>'); }

echo(
'</table></center>'); 

 
?>


Hint: if you want to dispaly all hexadecimal values from "0" to "FF" ; don't write "manually" 255 values; try this script I've made, copy and paste the result displayed on your browser:


<?php echo "$color = Array(";

//relatively to the chart's script

for ($a $a 255 $a++)

// a is between 0 and hexadecimal FF

{

$b dechex($a) ;

// b converts a to hexadecimal

if ($a 16 )

// if a < F (Hx)

{

    
$b "0".$b ;

//for example: "9" becomes "09" ; "B" => "0B", etc.

}

$c "'".$b."'," ;

echo 
$c ;

}

echo 
"'ff');"// to avoid the comma "," at the end  ?>


To compress page to gz format, and so make the page faster to execute; type at the top of the page:

<?php  



ob_start
'ob_gzhandler' );



 
?>


Very efficient

Related download: PHP Color Chart - noversion

Downloaded 346 times

Click here to download the source
8 kb

UP
Home

 

 

No comments yet; be the first to post

 

 
Global note :: 3.63/5 Total votes :: 8

Rate this article

Excellent
Very Good
Good
Fair
Poor



Page loaded in 0.571 seconds

Swobodin's Do All 0.1 GNU/GPL - ©2004 Swobodin
http://www.swobodin.tk