PHP code example of hallindavid / manny

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

    

hallindavid / manny example snippets


use Manny;

Manny::phone("8008008000"); // Returns: 800-800-8000


use Manny;
Manny::phone("8008008000"); // Returns: 800-800-8000


/**
* @param string $number
* @param array $options
*
*
* Default Options
*
*    $default_options = [
*        'showCountryCode'         => false,
*        'showAreaCode'            => true,
*        'showExchange'            => true,
*        'showLine'                => true,
*        'showExtension'           => false,
*        'prefix'                  => false,
*        'country_area_delimiter'  => false,
*        'area_exchange_delimiter' => '-',
*        'exchange_line_delimiter' => '-',
*        'line_extension_delimiter'=> ' ext. ',
*    ];
* @return string
*/
function phone($number, $options)

Manny::phone("8008008000"); 
//outputs 800-800-8000

class Brack10 extends Manny\Phone
{
    public function __construct($text)
    {
        parent::__construct($text);
        $this->showCountryCode = false;
        $this->showAreaCode = true;
        $this->showExchange = true;
        $this->showLine = true;
        $this->showExtension = false;
        $this->prefix = false;
        $this->country_area_delimiter = '(';
        $this->area_exchange_delimiter = ') ';
        $this->exchange_line_delimiter = '-';
        $this->line_extension_delimiter = ' ext. ';
    }
}

$phone = new Brack10("123456789123456");
$phone->format();
//Returns: (234) 567-8912

/**
 * @param string $target
 * @param string $pattern
 * @return string
 */
function mask($target, $pattern)

//US Social Security Number
Manny::mask("987654321", "111-11-1111"); //returns "987-65-4321"

//US Zip-code
Manny::mask("The whitehouse zip code is: 20500", "11111"); //returns "20500"

//Canada Postal Code
Manny::mask("K1M1M4", "A1A 1A1"); //

//outputs 987-65-4321

/**
 * @param array $target - should be key-val associative array
 * @param array $elements - should be flat array with desired key names from target array
 * @param array $defaults (optional) - key-val associative array which will be appended to extracted key-value pairs before returning
 * @return array
 */
function yoink($target, $elements, $defaults = null)

$array = ['id'  => '17', 'name'=> 'John Doe'];
$elements = ['name', 'role'];
$default_values = ['role'=> 'member'];
Manny::yoink($array, $elements, $default_values);  //Returns: ['name'=>'John Doe','role'=>'member'] ;

/**
 * @param string     $text    - the subject of our stripping
 * @param array|null $options - an array with the return types you'd like
 * 
 *  keys can   dot - keep periods
 *  dash - keep dashes/hyphens
 *  space - keep spaces
 *  underscore - keep underscores
 *  pipe - keep pipe characters
 *  bracket - keep square brackets []
 *  parenthesis - keep parenthesis ()
 *  curly - keep curley braces (useful for handlebar syntax ex. {{ thing }} 
 * 
 * @return string
 */
function stripper($text, $options = null)

$string = 'With only 5-10 hours of development, Dave built Manny, saving him atleast 10 seconds per day!';
$config = ['num', 'alpha', 'space'];
Manny::stripper($string,$config); 
//Returns: 'With only 510 hours of development Dave built Manny saving him atleast 10 seconds per day';

$alt_config = ['num'];
Manny::stripper($string,$alt_config); 
//Returns: '51010';

$string = 'I only want to "keep" the alpha, num, and spaces for this string!';
$options = ['alpha', 'num', 'space']
Manny::keep()
//Returns: 'I only want to keep the alpha num and spaces for this string'

    /**
     * @param string $text - the subject of our crumbling
     * @param array $crumbs - an array of positive integers
     * @param bool $appendExtra - keys can 

Manny::crumble("18008008000888", [1,3,3,4])
//Output: ["1","800","800","8000"];

//with append extra
Manny::crumble("18008008000888", [1,3,3,4],true)
//Output: ["1","800","800","8000", "888"];

    /**
     * @param int|float|string $num - the numerator
     * @param int|float|string $denom - the denominator
     * @param int $precision - keys can 

Manny::percent(1,8);
//Output: 12.5;