PHP code example of flextype-components / number

1. Go to this page and download the library: Download flextype-components/number library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

flextype-components / number example snippets


use Flextype\Component\Number\Number;

echo Num::format_bytes('204800');     // 200 kB
echo Num::format_bytes('214901', 1);  // 209.9 kB
echo Num::format_bytes('2249010', 1); // 2.1 MB
echo Num::format_bytes('badbyteshere'); // false

echo Number::convertToBytes('200K');  // 204800
echo Number::convertToBytes('5MiB');  // 5242880
echo Number::convertToBytes('2.5GB'); // 2684354560

echo Number::quantity(7000); // 7K
echo Number::quantity(7500); // 8K
echo Number::quantity(7500, 1); // 7.5K

if (Number::between(2, 10, 5)) {
    // do something...
}

if (Number::even(2)) {
    // do something...
}

if (Number::greaterThan(2, 10)) {
     // do something...
}

if (Number::smallerThan(2, 10)) {
     // do something...
}

if (Number::maximum(2, 10)) {
     // do something...
}

if (Number::minimum(2, 10)) {
     // do something...
}

if (Number::odd(2)) {
     // do something...
}

// ************5678
echo Number::maskString('1234567812345678', '************0000');

// **** **** **** 5678
echo Number::maskString('1234567812345678', '**** **** **** 0000');

// **** - **** - **** - 5678
echo Number::maskString('1234567812345678', '**** - **** - **** - 0000', ' -');

// (123) 456-7890
echo Number::format('1234567890', '(000) 000-0000');

// 123.456.7890
echo Number::format('1234567890', '000.000.0000');

// (061) 234 5678
echo Number::formatPhone('0612345678');

// (06) 123 456 78
echo Number::formatPhone('0612345678', '(00) 000 000 00');

// **** **** **** 2938
echo Number::maskСreditСard('1234263583742938');

// 1234 **** **** ****
echo Number::maskСreditСard('1234123412341234', '0000 **** **** ****');

// 12-34
echo Number::formatExp('1234');

// 12/34
echo Number::formatExp('1234', '00/00');