<?php
function numberToWords($number)
{
    $no = floor($number);
    $point = round($number - $no, 2) * 100;

    $words = array(
        '0' => '', '1' => 'one', '2' => 'two', '3' => 'three', '4' => 'four',
        '5' => 'five', '6' => 'six', '7' => 'seven', '8' => 'eight', '9' => 'nine',
        '10' => 'ten', '11' => 'eleven', '12' => 'twelve', '13' => 'thirteen',
        '14' => 'fourteen', '15' => 'fifteen', '16' => 'sixteen',
        '17' => 'seventeen', '18' => 'eighteen', '19' => 'nineteen',
        '20' => 'twenty', '30' => 'thirty', '40' => 'forty',
        '50' => 'fifty', '60' => 'sixty', '70' => 'seventy',
        '80' => 'eighty', '90' => 'ninety'
    );

    $digits = array('', 'hundred', 'thousand', 'lakh', 'crore');
    $str = array();
    $i = 0;

    while ($no > 0) {
        $divider = ($i == 1) ? 10 : 100;
        $number_part = $no % $divider;
        $no = floor($no / $divider);

        if ($number_part) {
            $plural = ($i && $number_part > 9) ? ' ' : '';
            $hundred = ($i == 1 && !empty($str)) ? ' and ' : ' ';

            if ($number_part < 21) {
                $str[] = $words[$number_part] . ' ' . $digits[$i] . $hundred;
            } else {
                $str[] = $words[floor($number_part / 10) * 10] . ' ' .
                         $words[$number_part % 10] . ' ' . $digits[$i] . $hundred;
            }
        } else {
            $str[] = '';
        }

        $i++;
    }

    $result = implode('', array_reverse($str));

    if ($point > 0) {
        $result .= ' and ' . $words[floor($point / 10) * 10] . ' ' . $words[$point % 10] . ' paise';
    }

    return ucwords(trim($result)) . ' only';
}
