Convert number to words in PHP

Today, We want to share with you convert number to words in php.In this post we will show you convert number to rupees in php, hear for How to convert Amount in Digits or Numbers to Words using PHP? we will give you demo and example for implement.In this post, we will learn about convert number to words in codeigniter with an example.

PHP number to word converter using Indian numbering system

There are the Following The simple About PHP Exercise: Convert word to digit Full Information With Example and source code.

As I will cover this Post with live Working example to develop convert number to words in indian rupees in php, so the convert any digit or number to Word by using the only PHP is used for this example is following below.

Read Also:  How to convert number to words in codeigniter?

PHP Code Snippets

Copy the below full source code and Call the function & Display Numbers to Words
index.php

<?php
function numberTowords($num)
{

	$singles = array(
	0 =>"ZERO",
	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",
	"014" => "FOURTEEN"
	);

	$tens = array( 
	0 => "ZERO",
	1 => "TEN",
	2 => "TWENTY",
	3 => "THIRTY", 
	4 => "FORTY", 
	5 => "FIFTY", 
	6 => "SIXTY", 
	7 => "SEVENTY", 
	8 => "EIGHTY", 
	9 => "NINETY" 
	); 

	$hundreds = array( 
	"HUNDRED", 
	"THOUSAND", 
	"MILLION", 
	"BILLION", 
	"TRILLION", 
	"QUARDRILLION" 
	); 

	/*limit t quadrillion */
	$num = number_format($num,2,".",","); 
	$num_arr = explode(".",$num); 
	$wholenum = $num_arr[0]; 
	$numberofdesimal = $num_arr[1]; 
	$whole_arr = array_reverse(explode(",",$wholenum)); 
	krsort($whole_arr,1); 
	$express_number = ""; 
	foreach($whole_arr as $key => $i){
		
	while(substr($i,0,1)=="0")
			$i=substr($i,1,5);
	if($i < 20){ 
	/* echo "getting:".$i; */
	$express_number .= $singles[$i]; 
	}elseif($i < 100){ 
	if(substr($i,0,1)!="0")  $express_number .= $tens[substr($i,0,1)]; 
	if(substr($i,1,1)!="0") $express_number .= " ".$singles[substr($i,1,1)]; 
	}else{ 
	if(substr($i,0,1)!="0") $express_number .= $singles[substr($i,0,1)]." ".$hundreds[0]; 
	if(substr($i,1,1)!="0")$express_number .= " ".$tens[substr($i,1,1)]; 
	if(substr($i,2,1)!="0")$express_number .= " ".$singles[substr($i,2,1)]; 
	} 
	if($key > 0){ 
	$express_number .= " ".$hundreds[$key]." "; 
	}
	} 
	if($numberofdesimal > 0){
	$express_number .= " and ";
	if($numberofdesimal < 20){
	$express_number .= $singles[$numberofdesimal];
	}elseif($numberofdesimal < 100){
	$express_number .= $tens[substr($numberofdesimal,0,1)];
	$express_number .= " ".$singles[substr($numberofdesimal,1,1)];
	}
	}
	return $express_number;
}
extract($_POST);
if(isset($convert))
{
echo "<p align='center' style='color:blue'>".numberTowords("$num")."</p>";
}
?>
<!DOCTYPE html>
<html>
	<head>
		<title>Conver Number to Words in PHP - www.pakainfo.com</title>
	</head>
	<body>
		<form method="post">
			<table border="0" align="center">
				<tr>
				<td>Enter Your Numbers</td>
				<Td><input type="text" name="num" value="<?php if(isset($num)){echo $num;}?>"/></Td>
				</tr>
				<tr>
				<td colspan="2" align="center">
				<input type="submit" value="Conver Number to Words" name="convert"/>
				</td>
				</tr>
			</table>
        </form> 

	</body>
</html>

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about convert number to words in php.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.