PHP code example of corpsee / nameless-utilities

1. Go to this page and download the library: Download corpsee/nameless-utilities 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/ */

    

corpsee / nameless-utilities example snippets


use Nameless\Utilities\ArrayHelper;

echo ArrayHelper::toString([1, 2, 3]); // Prints '1, 2, 3', ', ' is default separator
echo ArrayHelper::toString([1, 2, 3], ':'); // Prints '1:2:3'

$array = [
    'one'   => 1,
    'two'   => 2,
    'three' => 3,
];
echo ArrayHelper::get($array, 'four', 4); // Prints '4' (4)

use Nameless\Utilities\DateTimeHelper;

echo DateTimeHelper::humanize(121.001); // Prints '2 minute 1 second 1 millisecond'

use Nameless\Utilities\DateTimeHelper;

$localization = [
    ['мкс', 'мкс'],
    ['мс', 'мс'],
    ['с', 'с'],
    ['мин', 'мин'],
    ['ч', 'ч'],
    ['д', 'д'],
    ['мес', 'мес'],
    ['г', 'г'],
];

echo DateTimeHelper::humanize(121, $localization); // Prints '2 мин 1 с'

use Nameless\Utilities\FileSizeHelper;

echo FileSizeHelper::humanize(1000000000); // Prints '953.67MB'
echo FileSizeHelper::unhumanize('954MB');  // Prints '1000341504' (bytes)

use Nameless\Utilities\PathHelper;

echo PathHelper::toURL('/base/path/to/url', '/base'); // Prints '/path/to/url'

use Nameless\Utilities\StringHelper;

var_dump(StringHelper::startWith('example', 'exa'));  // Prints true
var_dump(StringHelper::endWith('example', 'mplee'));  // Prints true
var_dump(StringHelper::contains('example', 'xampl')); // Prints true

echo StringHelper::cut('example', 6);             // Prints 'exampl...', '...' is default suffix
echo StringHelper::cutWords('simple example', 1); // Prints 'example...', '...' is default suffix

echo StringHelper::transliterate('очень простой пример', 'Russian-Latin/BGN');     // Prints transliterated 'ochen prostoj primer'
echo StringHelper::standardize('очень простой  Пример', 'Russian-Latin/BGN');      // Prints standardizated 'ochen_prostoj_primer', '_' is default words separator
echo StringHelper::standardize('очень простой  Пример', 'Russian-Latin/BGN', '-'); // Prints 'ochen-prostoj-primer', use '-' for slugify string

var_dump(StringHelper::toArray('1,2,3,')); // Prints Array ['1', '2', '3'], ',' is default separator

echo StringHelper::snakecaseToCamelcase('snake_case');       // Prints 'SnakeCase'
echo StringHelper::snakecaseToCamelcase('snake_case', true); // Prints 'snakeCase'
echo StringHelper::camelcaseToSnakecase('CamelCase');        // Prints 'camel_case'

use Nameless\Utilities\UrlHelper;

echo UrlHelper::toPath('/path/to/url', '/base'); // Prints '/base/path/to/url'



$num1 = 0;         // (string) 0 => '0'
$num2 = -0.000005; // (string) -0.000005 => '-5.05E-6'

echo bcadd($num1, $num2, 6); // => '0.000000'

setlocale(LC_NUMERIC, 'de_DE'); // uses a decimal comma
$num2 = 1.2;                    // (string) 1.2 => '1,2'

echo bcsub($num1, $num2, 1);    // => '0.0'


use Nameless\Utilities\BcMathHelper;

var_dump(BcMathHelper::add('0.000005', '0.000005', 5));  // (float)0.00001
var_dump(BcMathHelper::add('0,000005', '0,000005', 5));  // (float)0.00001
var_dump(BcMathHelper::add(0.000005, 0.000005, 5));  // (float)0.00001
var_dump(BcMathHelper::add('5.0E-6', '5.0E-7', 5));  // (float)0.00001

var_dump(BcMathHelper::sub(0.000005, 0.000001, 5));  // (float)0.000004

var_dump(BcMathHelper::mul(0.000005, 0.000002, 11));  // (float)0.00000000001

var_dump(BcMathHelper::div(0.000005, 0.000002, 2));  // (float)2.50

var_dump(BcMathHelper::comp(0.000005, 0.000002, 6));  // (int)1