Login   Register  
PHP Classes
elePHPant
Icontem

File: example2.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Ignatius Teo  >  Sample Data Generator  >  example2.php  >  Download  
File: example2.php
Role: Example script
Content type: text/plain
Description: Advanced example
Class: Sample Data Generator
Generating random sample data based on rules
Author: By
Last change:
Date: 9 years ago
Size: 3,396 bytes
 

Contents

Class file image Download
<?php
/**
 * example2.php - Advanced example
 * Slightly more advanced random data sample generator
 * $Id: example2.php,v 1.3 2004/12/04 00:01:54 Owner Exp $
 */

include "tsample.php";

// some sample data
$male_firstnames = array (
    
"Adam""Bob""Charles""Dave""Edgar""Fred""Greg""Harry""Ian""James""Kingsley",
    
"Larry""Michael""Neil""Oscar""Patrick""Quentin""Roger""Steve""Tom""Uriah",
    
"Victor""Walter""Xander""Yanik""Zak"
);

$female_firstnames = array (
    
"Alice""Bianca""Cath""Diane""Ellen""Fran""Gerry""Helen""Imogen""Jane",
    
"Kelly""Lisa""Mary""Nancy""Olivia""Patricia""Rita""Sally""Tess""Uma",
    
"Victoria""Wilomena""Xandrine""Yumiko""Zoe"
);

$lastnames = array(
    
"Ableman""Ackerman""Burke""Barry""Cortes""Connor",
    
"Deane""Donohue""Ellis""Elliott""Fitzgerald""Fitzpatrick",
    
"Gregory""Goldsworthy""Hollis""Hodgkinson""Inch""James""Jones",
    
"Kennedy""Kelly""Lyon""Lynch""MacDonald""Murphy""Nye""Nielson",
    
"O'Connor""O'Neill""Patrick""Phillips""Quentin""Quinn""Riley""Ryan",
    
"Stephens""Smith""Thomas""Tucker""Unger""Unwin""Victor""Voss",
    
"Warne""Waugh""Xavier""Yeoman""Zachariah"
);

$streets = array(
    
"First St""Second St""Third St""Fourth St""Fifth St",
    
"Sixth Ave""Seventh Ave""Eigth Ave""Ninth Ave""Tenth Ave",
    
"Oak Court""Maple Court""Red Gum Court""Teak Court""Jarrah Court""Mahogany Court",
    
"Poplar Circuit""Conifer Circuit""Fir Circuit""Elm Circuit""Pine Circuit",
    
"Cedar Grove""Box Grove""Olive Grove",
);

// ruleset to generate male names between the ages of 18-50
// living in Sydney, NSW
$rule_set_A = array(
    
"firstname"         => array("choice"$male_firstnames),
    
"lastname"            => array("choice"$lastnames),
    
"gender"            => array("as_is""male"),
    
"cdate"             => array("datetime"),
    
"birthdate"            => array("dob"1850),

    
// combining the results of 2 rules
    
"address"            => array(array("range"1999), array("choice"$streets)),
    
"city"                => array("as_is""Sydney"),
    
"state"                => array("as_is""NSW"),
    
"zip"                => array("range"20002100),
    
"phone"                => array("range"2359999923899999),
);

// ruleset to generate female names between the ages of 18-50
// living in Sydney, NSW
$rule_set_B = array(
    
"firstname"         => array("choice"$female_firstnames),
    
"lastname"            => array("choice"$lastnames),
    
"gender"            => array("as_is""female"),
    
"cdate"             => array("datetime"),
    
"birthdate"            => array("dob"1850),
    
"address"            => array(array("range"1999), array("choice"$streets)),
    
"city"                => array("as_is""Sydney"),
    
"state"                => array("as_is""NSW"),
    
"zip"                => array("range"20002100),
    
"phone"                => array("range"2359999923899999),
);

print 
"<pre>";
// generate 10 records for ruleset A
print_r(TSample::generate($rule_set_A10));

// generate a random number of records for ruleset B
print_r(TSample::generate($rule_set_BTSample::range(1,100)));
print 
"</pre>";
?>