PHP Convert currency into number to words string to money conversion

PHP Convert currency into number to words – string to money conversion

In this Post We Will Explain About is PHP Convert currency into number to words – string to money conversion With Example and Demo.

Welcome on Pakainfo.com – Examples ,The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to php – Converting Integer String to Money Format

In this post we will show you Best way to implement how to convert currency into a string in php, hear for How to php – How to convert amount in number to words with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Read Also:  PHP OOPS - MySQL connecting Insert update delete select Fetch Data

php – Converting Integer String to Money Format

HTML Input Form

<form method="post">
 Enter Number: </br></br>
 
</form>

First Array

    $first_list = array('', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven',
        'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'
    );

Second Array

$second_list = array('', 'ten', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety', 'hundred');

Third Array

    $third_list = array('', 'thousand', 'million', 'billion'
    );

Full Example – PHP – How to convert amount in number to words

<?php
error_reporting(0);
function convertNumberToWord($your_num = false)
{
    $your_num = str_replace(array(',', ' '), '' , trim($your_num));
    if(! $your_num) {
        return false;
    }
    $your_num = (int) $your_num;
    $out_words = array();
    $first_list = array('', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven',
        'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'
    );
    $second_list = array('', 'ten', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety', 'hundred');
    $third_list = array('', 'thousand', 'million', 'billion'
    );
    $total_your_numlength = strlen($your_num);
    $max_levels = (int) (($total_your_numlength + 2) / 3);
    $max_length = $max_levels * 3;
    $your_num = substr('00' . $your_num, -$max_length);
    $your_num_max_levels = str_split($your_num, 3);
    for ($i = 0; $i < count($your_num_max_levels); $i++) {
        $max_levels--;
        $total_hundreds = (int) ($your_num_max_levels[$i] / 100);
        $total_hundreds = ($total_hundreds ? ' ' . $first_list[$total_hundreds] . ' hundred' . ( $total_hundreds == 1 ? '' : 's' ) . ' ' : '');
        $tens = (int) ($your_num_max_levels[$i] % 100);
        $singles = '';
        if ( $tens  1) {
        $commas = $commas - 1;
    }
    $data= implode(' ', $out_words);
	return $data." ".'only';
}
if(isset($_POST['btn_submit'])){
echo "<p style="color:green">".convertNumberToWord($_POST['live_your_number'])."</p><br>";
}
?>
<form method="post">
 Enter Number: </br></br>
 
</form>

Example

I hope you have Got how to convert currency into a string in php And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.