Home > Uncategorized > easy graphical dice generator in PHP

easy graphical dice generator in PHP

Wednesday, July 28th, 2010 Cameron Leave a comment Go to comments

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>


Tags: , ,
  1. Thursday, July 29th, 2010 at 17:26 | #1

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

    - Robbie

    • Cameron
      Thursday, July 29th, 2010 at 22:17 | #2

      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.

  1. Wednesday, July 28th, 2010 at 21:37 | #1