So lets say we have a string whos value could be
1,234 or
12,567 or
1,123,456 or
17,865,345,198
Ok so I can figure out Millions.
<?php
$value = '123,234,593';
$pattern = '/,\d{3},\d{3}$/i';
$newvalue = ' Million';
echo preg_replace($pattern , $newvalue, $value);
?>
But I want to echo other value denominators too, so if the value = 123,456 I would like to echo 123 Thousand
if it is 1,234,567,123 I would like to echo 1.24 Billion
etc.
If I am not wrong, you want to convert a currency amount to words.
Use substr_count to find the number of commas in the amount.
One comma = thousand
Two commas = millions
Three commas = billions
Use case switch to set the appropriate value here. Let this be x.
Next use strpos to find the number of characters to the left of the first instance of a comma in the amount. Let this be y.
Now use another function to get the characters between the first and second instance of a comma. Let this be z.
Your final answer should be something like = $x.$y.$z
Thanks, but not what I am after 
<?php $value = '176,987'; $thousand = (substr($value, 0, -4) + 1)."k"; echo $thousand; ?>
I can make you a complete function including million and billion if you want.
Thanks Sushi ( http://peter-ajtai.com/examples/numbers.php ) Really long winded but kind of thing, just a tad too heavy weight for my liking.
Crakken I will have a play with that thankyou
Well, there you go: http://snippi.com/s/98pab35
In case you don’t have the original value with commas, use number_format.
Crakken said
Well, there you go: http://snippi.com/s/98pab35
In case you don’t have the original value with commas, use number_format.
Awesome, thanks for doing that. Just what I was after.
Well … will play with number format, becuase I would like to show to nearest cpl of dec places ( kind of thang )
Like 1.78 Billion etc
Seriously great , appreciate that
SportTipsWorld said
Well … will play with number format, becuase I would like to show to nearest cpl of dec places ( kind of thang )
Lol, I couldn’t understand that part, but no problem.
s4nji said
Here, I made one with preg_match_all, pretty much worked
Sanji thats pretty awesome work, may i use your code too. thankyou 
