Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4: */
3
//
4
// +----------------------------------------------------------------------+
5
// | PHP version 4                                                        |
6
// +----------------------------------------------------------------------+
7
// | Copyright (c) 1997-2003 The PHP Group                                |
8
// +----------------------------------------------------------------------+
9
// | This source file is subject to version 3.0 of the PHP license,       |
10
// | that is bundled with this package in the file LICENSE, and is        |
11
// | available at through the world-wide-web at                           |
12
// | http://www.php.net/license/3_0.txt.                                  |
13
// | If you did not receive a copy of the PHP license and are unable to   |
14
// | obtain it through the world-wide-web, please send a note to          |
15
// | license@php.net so we can mail you a copy immediately.               |
16
// +----------------------------------------------------------------------+
17
// | Authors: Piotr Klaban                                                |
18
// +----------------------------------------------------------------------+
19
//
20
 
21
/**
22
 * Test script for Numbers::Words
23
 **/
24
 
25
error_reporting(E_ALL);
26
 
27
require_once('PEAR.php');
28
require_once('Numbers/Words.php');
29
 
30
$num = "1121771141";
31
 
32
$html_on = 0;
33
if (isset($_REQUEST)) {
34
  $html_on = 1;
35
}
36
if (isset($_REQUEST) && is_array($_REQUEST) && isset($_REQUEST['num'])) {
37
  $num = $_REQUEST['num'];
38
} elseif (isset($argv) && is_array($argv) && isset($argv[1])) {
39
  $num = $argv[1];
40
}
41
$html_on = 0;
42
 
43
$shownum = $num;
44
 
45
while (strlen($shownum) % 3 != 0) {
46
  $shownum = " " . $shownum;
47
}
48
 
49
$shownum = ereg_replace("(...)", "\\1 ", $shownum);
50
$shownum = ereg_replace(" $", "", $shownum);
51
 
52
if ($html_on)
53
    echo "<center>Test number: <b><u>$shownum</u></b></center><p>\n";
54
else
55
    echo sprintf("%42s", 'Test number: ') . $shownum . "\n\n";
56
 
57
$lang = Numbers_Words::getLocales();
58
$langs = array();
59
 
60
if ($html_on) {
61
?>
62
<center>
63
<table width="100%" border="1" cellspacing="0">
64
<tr>
65
  <th width="50">Symbol</th>
66
  <th width="100">Number system</th>
67
  <th width="100%">String</th>
68
</tr>
69
<?
70
}
71
 
72
foreach ($lang as $loc_symbol) {
73
  $classname = "Numbers_Words_" . $loc_symbol;
74
  @include_once("Numbers/Words/lang.${loc_symbol}.php");
75
}
76
 
77
reset($lang);
78
 
79
foreach ($lang as $loc_symbol) {
80
  $classname = "Numbers_Words_" . $loc_symbol;
81
  $obj =& new $classname;
82
  $ret = $obj->toWords($num);
83
  if (PEAR::isError($ret)) {
84
    if ($html_on) {
85
    }
86
    echo "Error ($loc_symbol): " . $ret->message . "\n";
87
    if ($html_on) {
88
    }
89
  } else {
90
    $loc_name = $obj->lang;
91
    $langs[$loc_symbol] = $loc_name;
92
    if ($html_on) {
93
      ?>
94
      <tr>
95
        <td align="center"><?php echo $loc_symbol; ?></td>
96
        <td><nobr><i><?php echo $loc_name; ?></i></nobr></td>
97
        <td><b><?php echo $ret; ?></b></td>
98
      </tr><?
99
    } else {
100
      echo sprintf("%30s: '", $loc_name . ' (' . $loc_symbol . ')') . $ret . "'\n";
101
    }
102
  }
103
}
104
 
105
reset($langs);
106
 
107
$num .= '.34';
108
$handle = new Numbers_Words();
109
 
110
while (list ($loc_symbol, $loc_name) = each ($langs)) {
111
  $ret = $handle->toCurrency($num, $loc_symbol);
112
  if (PEAR::isError($ret)) {
113
    if ($html_on) {
114
    }
115
    echo "Error ($loc_symbol): " . $ret->message . "\n";
116
    if ($html_on) {
117
    }
118
  } else {
119
    if ($html_on) {
120
      ?>
121
      <tr>
122
        <td align="center"><?php echo $loc_symbol; ?></td>
123
        <td><nobr><i><?php echo $loc_name; ?></i></nobr></td>
124
        <td><b><?php echo $ret; ?></b></td>
125
      </tr><?
126
    } else {
127
      echo sprintf("%30s: ", $loc_name . ' (' . $loc_symbol . ')') . $ret . "\n";
128
    }
129
  }
130
}
131
 
132
if ($html_on) {
133
?>
134
</table>
135
</center>
136
<?php
137
}
138
 
139
?>