Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 89541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:43:58+00:00 2026-05-10T22:43:58+00:00

In PHP, is there an easy way to convert a number to a word?

  • 0

In PHP, is there an easy way to convert a number to a word? For instance, 27 to twenty-seven.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T22:43:58+00:00Added an answer on May 10, 2026 at 10:43 pm

    I found some (2007/2008) source-code online and as it is copyright but I can use it freely and modify it however I want, so I place it here and re-license under CC-Wiki:

    <?php /**  * English Number Converter - Collection of PHP functions to convert a number  *                            into English text.  *  * This exact code is licensed under CC-Wiki on Stackoverflow.  * http://creativecommons.org/licenses/by-sa/3.0/  *  * @link     http://stackoverflow.com/q/277569/367456  * @question Is there an easy way to convert a number to a word in PHP?  *  * This file incorporates work covered by the following copyright and  * permission notice:  *  *   Copyright 2007-2008 Brenton Fletcher. http://bloople.net/num2text  *   You can use this freely and modify it however you want.  */  function convertNumber($number) {     list($integer, $fraction) = explode('.', (string) $number);      $output = '';      if ($integer{0} == '-')     {         $output = 'negative ';         $integer    = ltrim($integer, '-');     }     else if ($integer{0} == '+')     {         $output = 'positive ';         $integer    = ltrim($integer, '+');     }      if ($integer{0} == '0')     {         $output .= 'zero';     }     else     {         $integer = str_pad($integer, 36, '0', STR_PAD_LEFT);         $group   = rtrim(chunk_split($integer, 3, ' '), ' ');         $groups  = explode(' ', $group);          $groups2 = array();         foreach ($groups as $g)         {             $groups2[] = convertThreeDigit($g{0}, $g{1}, $g{2});         }          for ($z = 0; $z < count($groups2); $z++)         {             if ($groups2[$z] != '')             {                 $output .= $groups2[$z] . convertGroup(11 - $z) . (                         $z < 11                         && !array_search('', array_slice($groups2, $z + 1, -1))                         && $groups2[11] != ''                         && $groups[11]{0} == '0'                             ? ' and '                             : ', '                     );             }         }          $output = rtrim($output, ', ');     }      if ($fraction > 0)     {         $output .= ' point';         for ($i = 0; $i < strlen($fraction); $i++)         {             $output .= ' ' . convertDigit($fraction{$i});         }     }      return $output; }  function convertGroup($index) {     switch ($index)     {         case 11:             return ' decillion';         case 10:             return ' nonillion';         case 9:             return ' octillion';         case 8:             return ' septillion';         case 7:             return ' sextillion';         case 6:             return ' quintrillion';         case 5:             return ' quadrillion';         case 4:             return ' trillion';         case 3:             return ' billion';         case 2:             return ' million';         case 1:             return ' thousand';         case 0:             return '';     } }  function convertThreeDigit($digit1, $digit2, $digit3) {     $buffer = '';      if ($digit1 == '0' && $digit2 == '0' && $digit3 == '0')     {         return '';     }      if ($digit1 != '0')     {         $buffer .= convertDigit($digit1) . ' hundred';         if ($digit2 != '0' || $digit3 != '0')         {             $buffer .= ' and ';         }     }      if ($digit2 != '0')     {         $buffer .= convertTwoDigit($digit2, $digit3);     }     else if ($digit3 != '0')     {         $buffer .= convertDigit($digit3);     }      return $buffer; }  function convertTwoDigit($digit1, $digit2) {     if ($digit2 == '0')     {         switch ($digit1)         {             case '1':                 return 'ten';             case '2':                 return 'twenty';             case '3':                 return 'thirty';             case '4':                 return 'forty';             case '5':                 return 'fifty';             case '6':                 return 'sixty';             case '7':                 return 'seventy';             case '8':                 return 'eighty';             case '9':                 return 'ninety';         }     } else if ($digit1 == '1')     {         switch ($digit2)         {             case '1':                 return 'eleven';             case '2':                 return 'twelve';             case '3':                 return 'thirteen';             case '4':                 return 'fourteen';             case '5':                 return 'fifteen';             case '6':                 return 'sixteen';             case '7':                 return 'seventeen';             case '8':                 return 'eighteen';             case '9':                 return 'nineteen';         }     } else     {         $temp = convertDigit($digit2);         switch ($digit1)         {             case '2':                 return 'twenty-$temp';             case '3':                 return 'thirty-$temp';             case '4':                 return 'forty-$temp';             case '5':                 return 'fifty-$temp';             case '6':                 return 'sixty-$temp';             case '7':                 return 'seventy-$temp';             case '8':                 return 'eighty-$temp';             case '9':                 return 'ninety-$temp';         }     } }  function convertDigit($digit) {     switch ($digit)     {         case '0':             return 'zero';         case '1':             return 'one';         case '2':             return 'two';         case '3':             return 'three';         case '4':             return 'four';         case '5':             return 'five';         case '6':             return 'six';         case '7':             return 'seven';         case '8':             return 'eight';         case '9':             return 'nine';     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Is there an easy way to convert a number to a word
I assumed there'd be an easy way in PHP to convert a string like
In there an easy way to do this in PHP. I want to make
Is there an easy way to delete an element from an array using PHP,
Is there an easy-ish way to modify the webform-form-tpl.php template to show disclaimer text
is there an easy way to open and create a zip with PHP?
I develop PHP apps in Eclipse and I'm wondering, is there an easy way
Is there any easy way to move the records up and down using PHP.
Is there an easy way to marshal a PHP associative array to and from
is there an easy way to crawl open source php forums and put them

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.