Monday, 6 February 2012

php number to words


This script will convert number to words. E.g. 15 will be converted to a string fifteen. 
<?php/**
*  Function:   convert_number
*
*  Description:
*  Converts a given integer (in range [0..1T-1], inclusive) into
*  alphabetical format ("one", "two", etc.)
*
*  @int
*
*  @return string
*
*/ 
function convert_number($number)
{
    if ((
$number 0) || ($number 999999999))
    {
    throw new 
Exception("Number is out of range");
    }

    
$Gn floor($number 1000000);  /* Millions (giga) */
    
$number -= $Gn 1000000;
    
$kn floor($number 1000);     /* Thousands (kilo) */
    
$number -= $kn 1000;
    
$Hn floor($number 100);      /* Hundreds (hecto) */
    
$number -= $Hn 100;
    
$Dn floor($number 10);       /* Tens (deca) */
    
$n $number 10;               /* Ones */

    
$res "";

    if (
$Gn)
    {
        
$res .= convert_number($Gn) . " Million";
    }

    if (
$kn)
    {
        
$res .= (empty($res) ? "" " ") .
            
convert_number($kn) . " Thousand";
    }

    if (
$Hn)
    {
        
$res .= (empty($res) ? "" " ") .
            
convert_number($Hn) . " Hundred";
    }

    
$ones = array("""One""Two""Three""Four""Five""Six",
        
"Seven""Eight""Nine""Ten""Eleven""Twelve""Thirteen",
        
"Fourteen""Fifteen""Sixteen""Seventeen""Eightteen",
        
"Nineteen");
    
$tens = array("""""Twenty""Thirty""Fourty""Fifty""Sixty",
        
"Seventy""Eigthy""Ninety");

    if (
$Dn || $n)
    {
        if (!empty(
$res))
        {
            
$res .= " and ";
        }

        if (
$Dn 2)
        {
            
$res .= $ones[$Dn 10 $n];
        }
        else
        {
            
$res .= $tens[$Dn];

            if (
$n)
            {
                
$res .= "-" $ones[$n];
            }
        }
    }

    if (empty(
$res))
    {
        
$res "zero";
    }

    return 
$res;

Monday, 16 January 2012

What is microblog?


Microblogging is a broadcast medium in the form of blogging. A microblog differs from a traditional blog in that its content is typically smaller in both actual and aggregate file size. Microblogs "allow users to exchange small elements of content such as short sentences, individual images, or video links".
As with traditional blogging, microbloggers post about topics ranging from the simple, such as "what I'm doing right now," to the thematic, such as "sports cars." Commercial microblogs also exist, to promote websites, services and/or products, and to promote collaboration within an organization.
Some microblogging services offer features such as privacy settings, which allow users to control who can read their microblogs, or alternative ways of publishing entries besides the web-based interface. These may include text messaging, instant messaging, E-mail, or digital audio.