function convertNumber($values) { $originalNumber = $values["number"]; if (is_numeric($originalNumber)) { $numerals = "Roman"; $originalNumber = (int) $originalNumber; $convertedNumber = Numbers_Roman::toNumeral($originalNumber, true, true); } else { $numerals = "Arabic"; $originalNumber = preg_replace("/[^IVXLCDM]/i", "", $originalNumber); $convertedNumber = Numbers_Roman::toNumber($originalNumber); } echo "<p>{$originalNumber} in {$numerals} numerals is: {$convertedNumber}.</p>"; }
function pleac_Working_with_Roman_Numerals() { // PHP offers no native support for Roman Numerals. However, a 'Numbers_Roman' class // is available for download from PEAR: [http://pear.php.net/package/Numbers_Roman]. // Note the following 'include' directives are required: // // include_once('Numbers/Roman.php'); $roman = Numbers_Roman::toNumeral($arabic); $arabic = Numbers_Roman::toNumber($roman); // ---------------------------- $roman_fifteen = Numbers_Roman::toNumeral(15); $arabic_fifteen = Numbers_Roman::toNumber($roman_fifteen); printf("Roman for fifteen is: %s\n", $roman_fifteen); printf("Arabic for fifteen is: %d\n", $arabic_fifteen); }
/** * Process the value * * @param var $value The value to process/format * @return string The processed value * @access private */ function _process($value) { return Numbers_Roman::toNumeral($value); }
/** * A backwards compatibility alias for toNumeral() * * @access private */ function toRoman($num, $uppercase = true) { return Numbers_Roman::toNumeral($num, $uppercase); }
<?php // Make the Numbers_Roman package available require_once "Numbers/Roman.php"; // Retrieve current year $year = date("Y"); // Convert year to Roman numerals $romanyear = Numbers_Roman::toNumeral($year); // Output the copyright statement echo "Copyright © {$romanyear}";
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>1 to 100 in Roman numerals</title> <link rel="stylesheet" type="text/css" href="common.css" /> </head> <body> <h1>1 to 100 in Roman numerals</h1> <p> <?php require_once "Numbers/Roman.php"; for ($i = 1; $i <= 100; $i++) { echo Numbers_Roman::toNumeral($i, true, true) . "<br />"; } ?> </p> </body> </html>