Color Cube With PHP

PHP September 17th, 2008

This is not my original idea.. But it’s very useful. For this trick idea, I grab from some banner generator site. Sory I’m forgot about this site. Then, I try to modified it with my knowledge about PHP. With this trick, you can make simple color cube. Like you know, some site used JavaScript to make a color cube, but I’m not really familiar with JavaScript. So I did it using XHTML and PHP.

First you need select and option tag in XHTML to reprensentated color cube.  Make any option for RGB value and modified each option to RGB value. So user can choose some color by looking on this option. Lookout this script bellow.

For easy use, I separate this cube to mod. I save that script to mod_color_cube.php. Then I’ll combine it with include trick later.

Finish.. Ok, next make XHTML form to load and sent RGB value with POST method. Lookout this script bellow.

1
2
3
4
5
6
<form method="POST" action="process.php">
<select name="getRgb" size="1" class="createselect" onchange="UsersNeedAlwaysHelp()">
	<?include('mod_color_cube.php');?>
</select>
<input type="submit" value="Generate"/>
</form>

Save it to chooseColor.php. If this form submitted, it will send getRgb variable and value to process.php with POST method. Now let’s create process.php to parsing getRgb to Red, Green, and Blue values.

1
2
3
4
5
6
7
8
9
<?php
                //post variable getRgb with value for example getRgb="000,102,204"
		$getRgb=$_POST['getRgb']; 
		$comma=",";//separate by commas
		$rgb=split($comma,$getRgb); //get color value every space and make array
		$red=$rgb[0]; // $red=000
		$green=$rgb[1]; //$green=102
		$blue=$rgb[2]; //$blue=204
?>

For example I choose option R: 000, G: 102, B:204. Then option value (”000,102,204″) sent to process.php with POST method. With split function in PHP you can separate value by commas and save it into array ($rgb). Then $rgb[0] contain red value, $rgb[1] contain green value, and $rgb[2] contain blue value. That’s all^^

Sphere: Related Content

Tags: , ,
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...






Related Post:


Leave a Comment

Blogroll Link Update