How to Convert Number to Words in PHP Ajax

To Convert Number To Words in PHP Ajax, we use numfmt_create() and numfmt_format() function. Both functions are inbuilt PHP functions which also part of Human Language and Character Encoding Support.

These functions are the defined under the intL (Internationalization Functions) functions.

How to Convert Number to Words in PHP Ajax
How to Convert Number to Words in PHP Ajax

To Convert Number To Words, first, we create an HTML form where we take the number from the user and then send it the PHP file using Ajax with the POST method.

You can check live view below.

Before we start, we have to enable Intl extension on the PHP configuration file,

  • Open PHP configuration file (php.ini)
    • Path: C:\xampp\php\php.ini (if you use Xampp)
  • Remove semicolon (;) from “extension=intl” it.
  • Now restart the Apache server.
Enable intl extension PHP

Above are the necessary steps before the code run.

Here is 2 steps to Convert Number To Words in PHP using Ajax,

  • Create an HTML input and Ajax Script.
  • Create a PHP script to convert the input number to the word.

Create an HTML input With Ajax Script

Code Explanations:

  • Here we create an input element and button with an ID attribute.
  • On the Ajax file, we take the input data by ID attribute.
    • data: { numberInput: numberInput }
  • Then send the data using the POST method to our PHP snippet.
    • type: 'POST',
      url: 'numtoword.php',
      data: { numberInput: numberInput },
  • At last, take the success message from the PHP file and print it to the web page.
    • success: function(response) {
      $("#word").html(response);
      }

PHP script to convert the input number to word

numtoword.php

Code Explanations:

  • First, we check the input is set or not using the PHP isset() function.
  • Then we use numfmt_create() and numfmt_format() function to convert the number to the word.
  • At last, we print that out which show by Ajax on the page.

Live View of Convert Number to Words in Ajax

Convert Number to Words in Ajax

To know more about number format function on the PHP official site, https://www.php.net/manual/en/numberformatter.create.php

Also Check:

Happy Coding..!

Was this article helpful?
YesNo
My name is Bikash Kr. Panda. I own and operate PHPCODER.TECH, my native place in Odisha. I am a Web Programmer by profession and working on more than 50 projects to date. My passion is working on the web-based project using PHP and relate to all CMS and frameworks which is based on PHP.
Posts created 175

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top
mariobet - supertotobet - escort -

takip7.com

- milanobet giriş - gizabet giriş -
perabet giriş
- betkanyon giriş -

jojobet giriş

We are now accepting guest posting and creation of back-links.
This is default text for notification bar