PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Gordon Pettey   Numeral   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Numeral
Convert numbers between Roman and Hindu formats
Author: By
Last change: v1.2, added examples for setting object value per method.
Date: 15 years ago
Size: 1,154 bytes
 

Contents

Class file image Download
<?php

require_once('./class.numeral.php');

$num = new numeral(); // Numeral object.
$value = array(); // Array of values to test with.
$value[] = 2008;
$value[] = "1997";
$value[] = "MCCCXXXVII";
$value[] = 5000;
$value[] = "MCMLXXXVII";
$value[] = "1987";
$value[] = 60000;
$value[] = 500000;
$value[] = 16777216;
$value[] = "_M_M_M_M_M_M_M_M_M_M_M_M_M_M_M_M_D_C_C_L_X_X_VMMCCXVI";
// Underscore used in place of "overbar"

foreach($value as $var) { // Loop through test values using numeral
 
$num->setValue($var); // object with preset value.
 
echo $num->getValue()." - ";
 echo
$num->getType()." - ";
 echo
$num->getHindu()." - ";
 echo
$num->getRoman()." - ";
 echo
$num->convert()."<br />";
 echo
"<br />";
}

echo
"<br /><br /><br />";

$num2 = new numeral(); // Create a second numeral object.
foreach($value as $var) { // This time, loop through while setting the
 
echo $num2->getValue($var)." - "; // value as a parameter of each method.
 
echo $num2->getType($var)." - ";
 echo
$num2->getHindu($var)." - ";
 echo
$num2->getRoman($var)." - ";
 echo
$num2->convert($var)."<br />";
 echo
"<br />";
}

?>