Created
May 29, 2017 07:56
-
-
Save zhabinka/82a571098bab9212582b6d840f677379 to your computer and use it in GitHub Desktop.
Форматирование цены, установка валюты
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//[[price_format? &value=`[+price+]` ¤cy=`[+currency+]`]] | |
$value = isset($value) ? $value : ''; | |
$currency = isset($currency) ? $currency : ''; | |
if ($currency) { | |
switch ($currency) { | |
case USD: | |
$currency = '$'; | |
break; | |
case EUR: | |
$currency = '€'; | |
break; | |
case BYR: | |
$currency = 'руб.'; | |
break; | |
} | |
} | |
if ($value) { | |
$value = str_replace (' ', '', $value); | |
$value = preg_replace('/[^0-9]/', '', $value); | |
$value = number_format($value, 0, '', ' '); | |
} | |
return $currency . ' ' . $value; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment