PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Dave Smith   Lucky Numbers   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example Usage
Class: Lucky Numbers
Generate numbers from text using numerology
Author: By
Last change:
Date: 8 years ago
Size: 2,906 bytes
 

Contents

Class file image Download
<?php
/*
generate numbers from text using numerology
lucky number class 1.0
*/

//include class
include('luckynum.class.php');

//instantiate object
$luckyNum = new luckyNum();

//process user input
if( !empty($_REQUEST['posted']) ){
   
   
//flag to process each line instead of words
   
$useLine = ( empty($_REQUEST['useLine']) ) ? false : true;
   
   
//amount of numbers to find
   
$luckyNum->setNumberCount($_REQUEST['numberCount']);
   
   
//find numbers within this range
   
$luckyNum->setNumberRange($_REQUEST['lowRange'],$_REQUEST['highRange']);
   
   
//text to process
   
$luckyText = $_REQUEST['luckyText'];
   
   
//process text
    //note: you can run this method as many times as you wish with additional text before getting results
   
$luckyNum->processLuckyText($luckyText,$useLine);
   
   
//get results
   
$luckyResult = $luckyNum->getLuckyResult();
   
}else{
//or set form defaults
   
$_REQUEST['numberCount'] = $luckyNum->numberCount;
   
$_REQUEST['lowRange'] = $luckyNum->lowRange;
   
$_REQUEST['highRange'] = $luckyNum->highRange;
   
$_REQUEST['luckyText'] = '';
   
}

?>
<html>
    <head>
        <title>Lucky Number Testing</title>
    </head>
    <body>
        <h3>Generate Lucky Numbers</h3>
        <h4>The lucky number class uses numeroligy to generate numbers from any supplied text. By default each word will represent a number, however you can also set it so that each line represents a number.</h4>
        <form method="POST">
            Lucky Numbers to Generate:<br>
            <input type="text" name="numberCount" value="<?PHP echo $_REQUEST['numberCount'];?>"><br><br>
            Low Number Range:<br>
            <input type="text" name="lowRange" value="<?PHP echo $_REQUEST['lowRange'];?>"><br><br>
            High Number Range:<br>
            <input type="text" name="highRange" value="<?PHP echo $_REQUEST['highRange'];?>"><br><br>
            Your Lucky Text:<br>
            <textarea name="luckyText" style="width: 600px;height: 200px;"><?PHP echo $_REQUEST['luckyText'];?></textarea><br>
            <input type="checkbox" name="useLine"<?PHP echo ( empty($_REQUEST['useLine']) ) ? '' : ' checked';?>> Calculate lucky numbers from each line<br><br>
            <input type="hidden" name="posted" value="1"><input type="submit" name="formSubmit" value="Get Lucky Numbers">
       </form
<?php
if( !empty($luckyResult) ){
?>
<div>
            Lucky numbers requested: <?PHP echo $luckyResult['numberCount'];?><br>
            Lucky numbers found: <?PHP echo $luckyResult['resultCount'];?><br>
            Your lucky numbers: <strong><?PHP echo $luckyResult['resultSet'];?></strong>
        </div>
        <hr>
        <div>
            Object Values<br>
            <?PHP var_dump($luckyNum);?>
</div>
<?php
}
?>
</body>
</html>