Skip to content

Instantly share code, notes, and snippets.

@zhabinka
Created May 29, 2017 07:56
Show Gist options
  • Save zhabinka/82a571098bab9212582b6d840f677379 to your computer and use it in GitHub Desktop.
Save zhabinka/82a571098bab9212582b6d840f677379 to your computer and use it in GitHub Desktop.
Форматирование цены, установка валюты
<?php
//[[price_format? &value=`[+price+]` &currency=`[+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