Lottery Widget Source Code

This is a simple widget example which generates some lottery numbers (UK) and displays them in the sidebar.

<?php
/*
Plugin Name: UK lottery numbers
Plugin URI: http://www.getphp.net
Description: Generate numbers for the UK lottery
Author: shedboy
Version: 0.1
Author URI: http://www.getphp.net

Change History
0.1 : First version displays 6 numbers between 1 and 49

*/

//Lottery function, generates 6 random numbers between 1 and 49
function lottery($maxn = “49”,$maxb=”6″)
{
srand((double) microtime() * 1000000);
while (1>0)
{
$lottery[] = rand(1,$maxn);
$lottery = array_unique($lottery);
if (sizeof($lottery) == $maxb) break;
}
sort($lottery);
return implode(“, “,$lottery);
}
function widget_uklottery_init()
{

if ( !function_exists(‘register_sidebar_widget’))
return;
 
 function widget_uklottery()
 {
  # this  prints the widget
  echo $before_widget;
  echo $before_title;
  
  $lotterynums = lottery();
  echo “<h2>UK Lottery numbers generator</h2>”;
  echo “<br>$lotterynums<br><br><br>”;

  echo $after_title;
  echo $after_widget;
 }

register_sidebar_widget(‘UK lottery Widget’, ‘widget_uklottery’);
}

add_action(‘widgets_init’, ‘widget_uklottery_init’);
?>

LEAVE A REPLY

Please enter your comment!
Please enter your name here

*