Last active
December 20, 2021 10:08
-
-
Save ay4t/7551cf863532fceac81af8a1767224fb to your computer and use it in GitHub Desktop.
Formatter_helper
This file contains hidden or 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 | |
| /* | |
| * File: formatter_helper.php | |
| * Project: Helpers | |
| * Created Date: Su Dec 2021 | |
| * Author: Ayatulloh Ahad R | |
| * Email: ayatulloh@indiega.net | |
| * Phone: 085791555506 | |
| * ----- | |
| * Last Modified: Mon Dec 20 2021 | |
| * Modified By: Ayatulloh Ahad R | |
| * ----- | |
| * Copyright (c) 2021 Indiega Network | |
| * ----- | |
| * HISTORY: | |
| * Date By Comments | |
| * ---------- --- --------------------------------------------------------- | |
| */ | |
| /** | |
| * Membuat fungsi untuk memformat nomor telepon negara Indonesia | |
| * | |
| * @return void | |
| * @author Ayatulloh Ahad R - ayatulloh@indiega.net | |
| * https://github.com/ay4t | |
| **/ | |
| if (!function_exists('IndoPhone')) { | |
| function IndoPhone($string = '') | |
| { | |
| //menghilangkan tanda + | |
| $output = preg_replace('/(0|\+?\d{2})(\d{7,8})/', '$2', $string); | |
| //menghilangkan awalan 620 | |
| $split_detect = explode('620', $string); | |
| if (isset($split_detect[1])) { | |
| $output = str_replace('620', '', $string); | |
| } | |
| return '62' . $output; | |
| } | |
| } | |
| /** | |
| * Membuat fungsi untuk memformat dari mata uang tertentu | |
| * | |
| * @return void | |
| * @author Ayatulloh Ahad R - ayatulloh@indiega.net | |
| * https://github.com/ay4t | |
| **/ | |
| if (!function_exists('FormatCurrency')) { | |
| function FormatCurrency($amount = 0, $symbol = 'IDR') | |
| { | |
| /** fungsi untuk membuat dynamic decimal separator */ | |
| $explode_decimal = explode('.', $amount); | |
| $default_decimal = 2; | |
| if (isset($explode_decimal[1])) { | |
| $default_decimal = strlen($explode_decimal[1]) + 1; | |
| } | |
| /** PHP native formatter */ | |
| $formatter = new \NumberFormatter('en_US', \NumberFormatter::CURRENCY); | |
| $formatter->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $symbol); | |
| $formatter->setSymbol(\NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL, '.'); | |
| $formatter->setSymbol(\NumberFormatter::MONETARY_SEPARATOR_SYMBOL, ','); | |
| $formatter->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $default_decimal); | |
| return $formatter->format($amount); | |
| /* $money = Brick\Money\Money::of($amount, $symbol); | |
| return $money->formatWith($formatter); // US$5·000.00 */ | |
| } | |
| } | |
| /** | |
| * fungsi bantuan untuk memformat tanggal saat ini | |
| * | |
| * @return void | |
| * @author Ayatulloh Ahad R - ayatulloh@indiega.net | |
| * https://github.com/ay4t | |
| **/ | |
| if (!function_exists('isNow')) { | |
| function isNow() | |
| { | |
| $date = date('Y-m-d H:i:s'); | |
| return $date; | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fungsi ini untuk membuat format dengan Currency dan Symbol