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.

Read the rest of this entry »

Sphere: Related Content

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

Parsing With PHP [Part2]

PHP August 1st, 2008

This is the next parsing tutorial from part 1. After I learned two methods of parsing with PHP on part 1. I tried to create some PHP script from “PHP Programming Solution” that allow you to counting words in a string. Use a pattern to identify the individual words in the string, and then count how many times that pattern recurs:

1
2
3
4
5
6
7
8
9
<?php
// define string
$text = "The film begins with the Joker robbing a mob-owned bank with several other accomplices, whom he tricks into killing each other. That night, Batman impersonators attempt to interrupt a meeting of various mobsters and the Scarecrow. The real Batman appears, but suffers injuries which lead him to re-design the batsuit. Batman and Lieutenant James Gordon contemplate including new district attorney Harvey Dent in their plan to eradicate the mob, as he could be the public hero Batman cannot be. Bruce discovers that Harvey Dent is dating Rachel Dawes. Mob bosses meet to discuss Batman, Gordon, and Dent, while a Chinese mobster accountant, Lau, informs the gang leaders he has hidden their money to preempt a plan that Gordon has hatched to seize the mobsters' loot. The Joker arrives unexpectedly, offering to kill Batman for half their money.";
// decompose the string into an array of "words"
$words = preg_split('/[^0-9A-Za-z\']+/', $text, -1, PREG_SPLIT_NO_EMPTY);
// count number of words (elements) in array
// result: "139 words"
echo count($words) . " words";
?>

Read the rest of this entry »

Sphere: Related Content

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

Parsing With PHP [Part1]

PHP July 28th, 2008

Hehe.. I learn how to parsing with PHP. I read some books and find so many tricks to parsing text using PHP.. So I’ll try one by one^^ First, I tried to simple parsing with PHP. There are some technique for parsing that I learned today.

Parsing Comma-Separated List

How to parsing from comma-separated list then make it to array. First you can using explode() function. Lookout this example.

1
2
3
4
5
6
7
8
9
10
11
12
<?php
// define comma-separated list
$menu = "butter, milk, sugar, salt, flour, caramel";
// decompose string into array
// using comma as delimiter
$menu = explode(", ", $menu);
// iterate over array
// print individual elements
foreach ($menu as $i) {
echo $i . "<br />";
}
?>

Read the rest of this entry »

Sphere: Related Content

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

Blogroll Link Update