## Language PHP4

(graphic version using HTML tables)

Date: | 08/07/05 |

Author: | caminoix |

URL: | http://p2p.info.pl |

Comments: | 19 |

Info: | n/a |

Score: | (3.02 in 60 votes) |

<?php /* This script generates a series of HTML tables with cells in different colours. It is an utterly useless way to generate images on-the-fly. It shows how comfortable PHP can be compared to raw HTML. This script is 5KB long compared to over 14MB (!) of HTML output. If you like this script, I would be most grateful if you could visit http://p2p.info.pl/eng/index.php and click a Google ad ;) */ $letter["a"]=array(array(0,1,1,1,0), array(1,0,0,0,1), array(1,0,0,0,1), array(1,1,1,1,1), array(1,0,0,0,1)); $letter["b"]=array(array(1,1,1,1,0), array(1,0,0,0,1), array(1,1,1,1,0), array(1,0,0,0,1), array(1,1,1,1,0)); $letter["d"]=array(array(1,1,1,1,0), array(1,0,0,0,1), array(1,0,0,0,1), array(1,0,0,0,1), array(1,1,1,1,0)); $letter["e"]=array(array(1,1,1,1,1), array(1,0,0,0,0), array(1,1,1,1,0), array(1,0,0,0,0), array(1,1,1,1,1)); $letter["f"]=array(array(1,1,1,1,1), array(1,0,0,0,0), array(1,1,1,1,0), array(1,0,0,0,0), array(1,0,0,0,0)); $letter["g"]=array(array(0,1,1,1,1), array(1,0,0,0,0), array(1,0,1,1,1), array(1,0,0,0,1), array(0,1,1,1,0)); $letter["h"]=array(array(1,0,0,0,1), array(1,0,0,0,1), array(1,1,1,1,1), array(1,0,0,0,1), array(1,0,0,0,1)); $letter["i"]=array(array(0,1,1,1,0), array(0,0,1,0,0), array(0,0,1,0,0), array(0,0,1,0,0), array(0,1,1,1,0)); $letter["k"]=array(array(1,0,0,0,1), array(1,0,0,1,0), array(1,1,1,0,0), array(1,0,0,1,0), array(1,0,0,0,1)); $letter["l"]=array(array(1,0,0,0,0), array(1,0,0,0,0), array(1,0,0,0,0), array(1,0,0,0,0), array(1,1,1,1,1)); $letter["m"]=array(array(1,0,0,0,1), array(1,1,0,1,1), array(1,0,1,0,1), array(1,0,0,0,1), array(1,0,0,0,1)); $letter["n"]=array(array(1,0,0,0,1), array(1,1,0,0,1), array(1,0,1,0,1), array(1,0,0,1,1), array(1,0,0,0,1)); $letter["o"]=array(array(0,1,1,1,0), array(1,0,0,0,1), array(1,0,0,0,1), array(1,0,0,0,1), array(0,1,1,1,0)); $letter["p"]=array(array(1,1,1,1,0), array(1,0,0,0,1), array(1,0,0,0,1), array(1,1,1,1,0), array(1,0,0,0,0)); $letter["r"]=array(array(1,1,1,1,0), array(1,0,0,0,1), array(1,0,0,0,1), array(1,1,1,1,0), array(1,0,0,0,1)); $letter["s"]=array(array(0,1,1,1,1), array(1,0,0,0,0), array(0,1,1,1,0), array(0,0,0,0,1), array(1,1,1,1,0)); $letter["t"]=array(array(1,1,1,1,1), array(0,0,1,0,0), array(0,0,1,0,0), array(0,0,1,0,0), array(0,0,1,0,0)); $letter["u"]=array(array(1,0,0,0,1), array(1,0,0,0,1), array(1,0,0,0,1), array(1,0,0,0,1), array(0,1,1,1,0)); $letter["w"]=array(array(1,0,0,0,1), array(1,0,0,0,1), array(1,0,1,0,1), array(1,1,0,1,1), array(1,0,0,0,1)); $letter["y"]=array(array(1,0,0,0,1), array(0,1,0,1,0), array(0,0,1,0,0), array(0,0,1,0,0), array(0,0,1,0,0)); $letter["0"]=array(array(0,0,1,0,0), array(0,1,0,1,0), array(0,1,0,1,0), array(0,1,0,1,0), array(0,0,1,0,0)); $letter["1"]=array(array(0,0,1,0,0), array(0,1,1,0,0), array(0,0,1,0,0), array(0,0,1,0,0), array(0,0,1,0,0)); $letter["2"]=array(array(0,1,1,1,0), array(1,0,0,1,1), array(0,0,1,0,0), array(0,1,0,0,0), array(1,1,1,1,1)); $letter["3"]=array(array(1,1,1,1,0), array(0,0,0,0,1), array(0,1,1,1,0), array(0,0,0,0,1), array(1,1,1,1,0)); $letter["4"]=array(array(1,0,0,0,1), array(1,0,0,0,1), array(1,0,0,0,1), array(1,1,1,1,1), array(0,0,0,0,1)); $letter["5"]=array(array(1,1,1,1,1), array(1,0,0,0,0), array(1,1,1,1,0), array(0,0,0,0,1), array(1,1,1,1,0)); $letter["6"]=array(array(0,1,1,1,1), array(1,0,0,0,0), array(1,1,1,1,0), array(1,0,0,0,1), array(0,1,1,1,0)); $letter["7"]=array(array(1,1,1,1,1), array(0,0,0,1,0), array(0,0,1,0,0), array(0,1,0,0,0), array(1,0,0,0,0)); $letter["8"]=array(array(0,1,1,1,0), array(1,0,0,0,1), array(0,1,1,1,0), array(1,0,0,0,1), array(0,1,1,1,0)); $letter["9"]=array(array(0,1,1,1,0), array(1,0,0,0,1), array(0,1,1,1,1), array(0,0,0,0,1), array(0,1,1,1,0)); $letter[","]=array(array(0,0,0,0,0), array(0,0,0,0,0), array(0,0,0,0,0), array(0,1,0,0,0), array(1,0,0,0,0)); $letter["."]=array(array(0,0,0,0,0), array(0,0,0,0,0), array(0,0,0,0,0), array(1,1,0,0,0), array(1,1,0,0,0)); function one_line($what_in_it){ global $letter; echo "<table cellspacing=\"0\">"; for ($y=0; $y<5; $y++){ echo "<tr>"; for ($i=0; $i<strlen($what_in_it); $i++){ for ($x=0; $x<5; $x++){ if ($letter[$what_in_it[$i]][$y][$x]==1) $colour="#000000"; else $colour="#ffffff"; echo "<td style=\"background-color:$colour\">"; echo "</td>"; } echo "<td style=\"background-color:#ffffff\"></td>"; } echo "</tr>"; } echo "<tr><td></td></tr>"; echo "</table>"; } for ($i=99; $i>0; $i--){ $i==1 ? $s="" : $s="s"; $i==1 ? $no="no more" : $no=$i-1; one_line("$i bottle$s of beer on the wall, $i bottle$s of beer."); one_line("take one down and pass it around, $no bottles of beer on the wall."); one_line(" "); } one_line("no more bottles of beer on the wall, no more bottles of beer."); one_line("go to the store and buy some more, 99 bottles of beer on the wall."); ?>

Download Source | Write Comment

Download Source | Write Comment

## Add Comment

Please provide a value for the fields **Name**,
**Comment** and **Security Code**.

This is a gravatar-friendly website.

E-mail addresses will **never** be shown.

Enter your e-mail address to use your gravatar.

*Please don't post large portions of code here! Use the form to submit new examples or updates instead!*

## Comments

Gieron said on 08/23/05 16:21:26

That was utterly useless, but so cool.

Wojtek said on 09/15/05 10:37:33

Windows Explorer could not handle more than 70 bottles.

caminoix said on 09/24/05 00:52:48

Gieron:

thanks

Wojtek:

sorry to hear that. i haven't used windows for quite a time. it works just fine on mepis with konqueror.

J Hunt said on 11/21/05 14:40:22

Very nice. However, it's against Google TOS to ask people to click on your ads. They can remove your account for that. Just so you know. JH

caminoix said on 01/30/06 13:28:53

anonymous:

well, it wasn't supposed to be taken so seriously i guess it would be better if it was considered rather as a joke than anything else. i know just too well there's no reasonable way to use it in real life. therefore, the lack of compatibility with lynx &c. is not so much a great flaw

J Hunt:

oh, i didn't know that. thanks for the tip hope they won't pay too much attention to that.

Chase-san said on 07/20/06 19:53:56

Hah, well, thats interesting to say the least.

My development server in conjunction with opera 9 had it rendered in about 60 seconds.

Grol said on 09/11/06 12:16:33

Very nice.

I've found little bug, it should render:

"take one down and pass it around, 1 bottle of beer on the wall."

but it renders

"take one down and pass it around, 1 bottles of beer on the wall."

Matt Nordhoff said on 10/03/06 11:16:08

Grol:

To fix that bug, you can replace the for loop at the bottom with this:

for ($i=99; $i>0; $i--){

$s1 = ($i === 1 ? '' : 's');

$s2 = ($i - 1 === 1 ? '' : 's');

$no = ($i === 1 ? 'no more' : $i - 1);

one_line("$i bottle$s1 of beer on the wall, $i bottle$s1 of beer.";

one_line("take one down and pass it around, $no bottle$s2 of beer on the wall.";

one_line(' ');

}

I have a modified copy up at http://www.mattnordhoff.com/junk/99bottlesofbeer.phps (see it in action at .php; it's only 12 bottles, so your browser should be safe) that uses a CSS class like anonymous suggested and the HTML for 99 bottles is only 5.2 MiB. Other than that, it's functionally almost the same; I just redid the whitespace and made a couple minor changes.

(This is the second time I've tried to post this comment. The first time, the page showed some error for a split second but then it disappeared. If it ends up appearing twice, sorry.)

Matt Nordhoff said on 10/03/06 11:20:44

Bah. That code was garbled a little. Just replace each of the two emoticons with a "". I also put it up at http://pastebin.ca/189644 .

Matt Nordhoff said on 10/03/06 11:22:42

Ack! Replace each of them with a closing parenthesis. Darnit.

Zapaty said on 11/04/06 15:27:06

Undefined index on line 182. :/

Sib said on 11/04/06 15:56:40

To fix that "Undefined index on line 182" error, add the space character to $letter :

$letter[" "]=array(array(0,0,0,0,0),

array(0,0,0,0,0),

array(0,0,0,0,0),

array(0,0,0,0,0),

array(0,0,0,0,0));

Zapaty said on 11/04/06 16:06:45

Or just replace

if ($letter[$what_in_it[$i]][$y][$x]==1)

by

if ($what_in_it[$i] == ' ') $colour="#ffffff";

elseif ($letter[$what_in_it[$i]][$y][$x]==1)

at line number 182.

Infthi said on 02/19/07 14:50:20

Fantastish!!!

Matt Nordhoff said on 04/07/07 05:58:26

Zapaty, adding a special case for one character is bad form. You might as well get rid of the entire array.

(Yeah, yeah, this is five months after the comment I'm replying to was posted... :P )

Tim said on 06/06/08 22:43:13

Fatal error: Maximum execution time of 60 seconds exceeded in C:\Programme\xampp\htdocs\bottles-825.php on line 185

very nice anyway.

edintheclouds said on 04/16/09 10:19:24

IE 7 crashed after refresh!

this is awesome said on 07/08/09 07:42:17

Saw this a long time ago - I just remembered it and looked it up again. Like the first comment said, utterly useless but sooo cool.

cheers

Shamit Kumar Tomar said on 12/27/09 06:09:52

Nicest thing I saw today.

I ran on my localhost with Opera 10 and it displayed it out in 30 seconds or so and ya, I can "view source" too without crashing. Yay !!! Opera FTW.