1. Go to this page and download the library: Download wandersonwhcr/zend-romans library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
wandersonwhcr / zend-romans example snippets
use Zend\Romans\Filter\RomanToInt as RomanToIntFilter;
use Zend\Romans\Filter\IntToRoman as IntToRomanFilter;
$value = 'MCMXCIX';
$filter = new RomanToIntFilter();
$value = $filter->filter($value); // 1999
$filter = new IntToRomanFilter();
$value = $filter->filter($value); // MCMXCIX
use Zend\Romans\Validator\Roman as RomanValidator;
$validator = new RomanValidator();
$result = $validator->isValid('MCMXCIX'); // true
$result = $validator->isValid('IAI'); // false
$messages = $validator->getMessages();
/*
$messages = [
'unknownToken' => 'Unknown token "A" at position 1',
];
*/
$result = $validator->isValid('XIIIX'); // false
$messages = $validator->getMessages();
/*
$messages = [
'invalidRoman' => 'Invalid Roman number "XIIX"',
];
*/
use InvalidArgumentException;
use Zend\Romans\Hydrator\Strategy\Roman as RomanHydratorStrategy;
$value = 'MCMXCIX';
$strategy = new RomanHydratorStrategy();
try {
$value = $strategy->hydrate($value); // 1999
$value = $strategy->extract($value); // MCMXCIX
} catch (InvalidArgumentException $e) {
// unable to convert
}
use Zend\Romans\View\Helper\Roman as RomanViewHelper;
$helper = new RomanViewHelper();
// Simple Access
echo $helper(1999); // MCMXCIX
// ... or Inside ViewRenderer
echo $this->roman(1999); // MCMXCIX