easy graphical dice generator in PHP

Just a simple little script which displays two die on screen. The faces are generated randomly, and are text-based, so no images required.

<html>

<head><title>Dice</title><head>

<body>

<?php

//Required code: This defines the dice array

$dice=array(

'<br>&nbsp;·&nbsp;<br>&nbsp;',

'·<br><br>&nbsp;&nbsp;·',

'·<br>&nbsp;·&nbsp;<br>&nbsp;&nbsp;·',

'·&nbsp;·<br><br>·&nbsp;·',

'·&nbsp;·<br>&nbsp;·<br>·&nbsp;·',

'···<br><br>···',

);

//End required code

?>

<!--FONT FOR CORRECT DISPLAYING-->

<font face='Lucida Console'>

<!--TABLE FOR MULTIPLE DICE-->

<table border='1'>

<tr>

<td><!--OUTPUT-->

<?php echo $dice[array_rand($dice)]; ?>

</td>

<td><!--OUTPUT-->

<?php echo $dice[array_rand($dice)]; ?>

<!--END EVERYTHING-->

</td>

</tr>

</table>

</font>

</body>

</html>

Advertisements

About Cameron
I'm a final year Computer Science/Information Systems major. Already finished my BA in Politics/Philosophy. I do web and software freelance on the side, while I finish studying. Hoping to be self-employed by the end of my degree, otherwise off into the real-world I go....

3 Responses to easy graphical dice generator in PHP

  1. Pingback: Tweets that mention easy graphical dice generator in PHP « whileloop -- Topsy.com

  2. Robbie says:

    Very cool, I like. Mind if I mention this on my new blog with a reference back to you?

    – Robbie

    • Cameron says:

      No problem. I did acquire it a few years ago, but I can’t remember if I found it intact, or pulled it together based out of multiple sources.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: