Esempio n. 1
0
<?php

include 'finum.php';
//we will need finum lib
$finum = new finum();
//intializing it
?>
<!DOCTYPE html>
<html>
    <head>
        <title>finum example page</title>
        <meta charset="utf-8">
        <style>
            h1 {margin:0; padding-bottom:6px; margin-bottom:35px; border-bottom:1px solid #ccc;}
            div.container {
                width:50%;
                margin-left:auto;
                margin-right:auto;
                -moz-border-radius:3px;
                -webkit-border-radius:3px;
                border-radius:3px;
                border:1px solid #ccc;
                padding:24px;
                font-family: 'Arial';
            }
            pre {
             
                padding:14px;
                color:#555555;
                margin:0;
                
Esempio n. 2
0
 function fi($input)
 {
     $error = 'Oh no! something went wrong :/';
     // put here your custom error
     $finum = new finum();
     //intializing finum inside function, because we will need in this function
     $nums = array('nolla', 'yksi', 'kaksi', 'kolme', 'neljä', 'viisi', 'kuusi', 'seitsemän', 'kahdeksan', 'yhdeksän', 'kymmenen');
     // 0-10
     $numwords = array('toista', 'kymmentä', 'sata', 'sataa', 'tuhat', 'tuhatta');
     $input = ltrim(strval($input), '0');
     $intput = intval($input);
     $len = strlen($input);
     switch ($len) {
         case 1:
             // * 1 (1 digit)
             return $nums[$intput];
             break;
         case 2:
             // * 10 (2 digits)
             if ($input == '10') {
                 return $nums[10];
             } else {
                 if ($input[0] == '1') {
                     return $nums[intval($input[1])] . $numwords[0];
                 } else {
                     if ($input[1] == '0') {
                         return $nums[intval($input[0])] . $numwords[1];
                         //eg. 40 = neljäkymmentä
                     } else {
                         return $nums[intval($input[0])] . $numwords[1] . ' ' . $nums[intval($input[1])];
                         //eg. 45 = neljäkymmentä viisi
                     }
                 }
             }
             break;
         case 3:
             // * 100 (3 digits)
             if ($input[1] . $input[2] == '00') {
                 if ($input[0] == '1') {
                     // 100
                     return $numwords[2];
                 } else {
                     // ?00
                     return $nums[intval($input[0])] . $numwords[3];
                 }
             }
             if ($input[0] == '1') {
                 if ($input[2] == '0') {
                     //1?0
                     return $numwords[2] . ' ' . $nums[intval($input[1])] . $numwords[1];
                 } elseif ($input[1] == '1') {
                     //11?
                     return $numwords[2] . ' ' . $nums[intval($input[2])] . $numwords[0];
                 } elseif ($input[1] == '0') {
                     //10?
                     return $numwords[2] . ' ' . $nums[intval($input[2])];
                 } else {
                     return $numwords[2] . ' ' . $nums[intval($input[1])] . $numwords[1] . $nums[intval($input[2])];
                 }
             } else {
                 //??? not 1??
                 if ($input[2] == '0') {
                     //fix for "kahdeksansataa viisikymmentäNOLLA"- bug
                     return $nums[intval($input[0])] . $numwords[3] . ' ' . $finum->fi($input[1] . $input[2]);
                     //i found better solution; just let it run again
                 } else {
                     if ($input[1] == '0') {
                         return $nums[intval($input[0])] . $numwords[3] . ' ' . $finum->fi($input[2]);
                     } else {
                         return $nums[intval($input[0])] . $numwords[3] . ' ' . $finum->fi($input[1] . $input[2]);
                     }
                 }
             }
             break;
         default:
             return $error;
             return 'Sorry, but, only 3 digits are supported at this time :(  (given ' . $len . ')';
     }
 }