PHP code example of ay4t / php-helpers

1. Go to this page and download the library: Download ay4t/php-helpers 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/ */

    

ay4t / php-helpers example snippets


use Ay4t\Helper\HP;

// Phone: format internasional
$phone = HP::Phone('081234567890', 'ID')->getResult();            // "+62 812-3456-7890"

// Phone: hanya integer (MSISDN)
$msisdn = HP::Phone('081234567890', 'ID')->onlyInteger(true)->getResult(); // "6281234567890"

// Currency: format mata uang
$amount = HP::Currency(1000000, 'IDR', 2)->getResult();

// Currency: terbilang (spell-out)
$terbilang = HP::Currency(1000000, 'IDR', 2)->counted()->getResult();

// Datetime (Carbon wrapper)
$now = HP::Datetime()::now()->toDateTimeString();

// Array helper
$names = HP::Array($data)->where('status', 'active')->pluck('name');

// String helper
$slug = HP::String('Hello World!')->slugify();                      // "hello-world"
$bool = HP::String('yes')->toBoolean();                            // true

// Math helper: probability check
$isLucky = HP::Math()->isChance(50);                               // true/false (50% chance)

// URL helper
$url  = HP::URL('https://example.com?a=1')->addQueryParam('b', 2)->getResult();

// HTML helper
$aTag = HP::HTML()->link('https://example.com', 'Visit');

// Security helper
$hashed = HP::Security()->hashPassword('secret');

// Validation helper
$isEmail = HP::Validation('[email protected]')->isEmail();
bash
composer