note 75145 deleted from function.number-format by cmb
| From: | cmb@php.net | Date: | Tue, 13 Nov 2018 11:38:49 +0000 |
| Subject: | note 75145 deleted from function.number-format by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-209691@lists.php.net to get a copy of this message | ||
Note Submitter: alx at inbox dot lv
----
enjoy the PHP!
<?php
function FormatPrice($price) {
$price = preg_replace("/[^0-9\.]/", "",
str_replace(',','.',$price));
if (substr($price,-3,1)=='.') {
$sents = '.'.substr($price,-2);
$price = substr($price,0,strlen($price)-3);
} elseif (substr($price,-2,1)=='.') {
$sents = '.'.substr($price,-1);
$price = substr($price,0,strlen($price)-2);
} else {
$sents = '.00';
}
$price = preg_replace("/[^0-9]/", "", $price);
return number_format($price.$sents,2,'.','');
}
?>