echo '<form action="num2txt.php" method="post">
<input type="text" name="a">
<input type="submit" value="Преобразовать">
</form>';
class Num2Txt {
var $nbr, $names, $x, $razryad;
function __construct()
{
if(is_numeric($_POST[a]))
$this->nbr = $_POST[a];
else
echo 'вводить только целые числа';
$this->names= array(array("","",""," десять"),array(" один","надцать"," сто"," одинадцать"),array(" два"," двадцать"," двести"," двенадцать"),array(" три"," тридцать"," триста"," тринадцать"),array(" четыре"," сорок"," четыреста"," четырнадцать"),array(" пять"," пятьдесят"," пятьсот"," пятнадцать"),array(" шесть"," шестьдесят"," шестьсот"," шестнадцать"),array(" семь"," семьдесят"," семьсот"," семнадцать"),array(" восемь"," восемьдесят"," восемьсот"," восемнадцать"),array(" девять"," девяносто"," девятьсот"," девятнадцать"));
$this->x = str_split($this->nbr);
$this->razryad = array(""," тыс. "," млн. "," млрд. ", " трлн. "," квдрлн. "," квнтлн. "," скстлн. "," сптлн. "," октлн. "," ннлн. "," дцлн. ");
}
function show_nbr()
{ echo $this->nbr."<br>"; }
function translate() {
for($i = strlen($this->nbr) - 1 ; $i >= 0 ; $i--)
{
$jump = false;
if($this->x[strlen($this->nbr) - 1 - $i] == 1 && $i%3 == 1)
{
echo $this->names[$this->x[strlen($this->nbr) - $i]][3];
echo $this->razryad[($i-1)/3];
$jump = true;
}
else
echo $this->names[$this->x[strlen($this->nbr) - 1 - $i]][$i%3];
if($i%3==0 && ($this->x[strlen($this->nbr) - $i-1] != 0 || $this->x[strlen($this->nbr) - $i-2] != 0 || $this->x[strlen($this->nbr) - $i-3] != 0))
echo $this->razryad[$i/3];
if($jump)
$i--;
}
}
}
$obj = new Num2Txt();
$obj->show_nbr();
$obj->translate();