totally useless code
Posted: Wed Nov 05, 2003 10:46 pm
hey, i was away for sometime. stuck with httpd and php 4.2 on my redhat. so i coded this. i didn't know where to put (general dicussion or php code) but it's more php codey. so what's the point, well, i don't see a code review section anywhere so i'd just put it here and ask what do you guys think about it? 
-Nay
ps: this is my first indented code ever! i started using indented coding after using gEdit in redhat since u can actually customize to add spaces rather than tabs. me uses 3 spaces
Code: Select all
<?php
$names = array("numbers", "letters", "characters"); // names of the following arrays
$numbers = range(0, 9); // makes an array from 0 to 9
$letters = range(a, z); // makes an array from a to z
$characters = array("~", "@", "#", '$', "%", "^", "&", "*", "(", ")"); // array of other characters
$decs = array("strong", "em", "u"); // array of the decoration tags, bold, italic and underline
function randCol() {
$c_letters = range(a, f); // valid color letters (a to f)
$c_numbers = range(0, 9); // valid color numbers (0 to 9)
$c_all = Array_merge($c_letters, $c_numbers); // joins the two arrays
$color = ""; // defines color to return, started empty
while(strlen($color) < 6) { // make sure that the color code IS 6 characters
$max = count($c_all); // gets max key of the array
$num = rand(0, $max); // produces a random number
$color .= $c_all[$num]; // adds the given value to "color"
}
return $color; // returns color
}
function randVal($array) {
shuffle($array); // shuffles the given array
$max = count($array) - 1; // gets the biggest KEY in the array
$num = rand(0, $max); // produces a random number
$val = $array[$num]; // defines a random value in the array to return
return $val; // returns the value
}
print <<< PAGE_START
<html>
<head>
<title>Rando!</title>
</head>
<body bgcolor="000000" onLoad="setTimeout('document.location = document.location', 2000)">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
PAGE_START;
// page starting HTML outputted
for($rows = 0; $rows < 20; $rows++) // make 20 rows
{
print " \n<tr>\n"; // start TR
for($cols = 0; $cols < 10; $cols++) // make 10 columns per row
{
$key = randVal($names); // gets a random array
$key = randVal(${$key}); // gets a random value out of the random array returned
$dec = randVal($decs); // gets a random decoration to apply
$color = randCol(); // makes a random color
print <<< COL
<td>
<span style="color:$color">
<$dec>
$key
</$dec>
</span>
<br />
</td>
COL;
}
print " </tr>\n\n"; // ends the row
}
print <<< PAGE_END
</table>
</body>
</html>
PAGE_END;
?>ps: this is my first indented code ever! i started using indented coding after using gEdit in redhat since u can actually customize to add spaces rather than tabs. me uses 3 spaces