note 51170 deleted from function.substr by nlopess
| From: | nlopess@php.net | Date: | Tue, 22 Mar 2005 15:46:54 +0000 |
| Subject: | note 51170 deleted from function.substr by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-86796@lists.php.net to get a copy of this message | ||
Note Submitter: dynax at xs4all dot nl
Reason: useless
----
This is a function I wrote. You might think of using substr() for writing a function like this,
which might be easier. I did it my own way:
<?php
function tomoney($x) {
$x = strrev($x);
$geld_strl = strlen($x);
for($i=0; $i<$geld_strl; $i+=3) {
if(@$x{$i} != null) $y[$i] = $x{$i};
if($geld_strl > $i+1) $y[$i] = $x{$i+1}.$y[$i];
if($geld_strl > $i+2) $y[$i] = $x{$i+2}.$y[$i];
}
$y = array_reverse($y);
return "€ ".implode(",",$y);
}
?>
Example:
<?php
tomoney(4334332432)
// returns: € 4,334,332,432
tomoney(1000)
// returns: € 1,000
?>