PHP code example of macocci7 / bash-colorizer

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

    

macocci7 / bash-colorizer example snippets


    

    

    use Macocci7\BashColorizer\Colorizer;

    Colorizer::echo("Hi, there!");
    Colorizer::echo(" How's it going with you?", PHP_EOL);
    

    Colorizer::echo("Hi, there!");
        ->echo(" How's it going with you?", PHP_EOL);
    

    $colorizer = new Colorizer;
    $colorizer->echo("Hi, there!")
        ->echo(" How's it going with you?", PHP_EOL);
    

    $config = [
        'attributes' => ['italic', 'bold'],
        'foreground' => 'black',
        'background' => 'green',
    ];

    Colorizer::config($config);
    Colorizer::echo("Hi, there!");
    

    Colorizer::config($config)
        ->echo("Hi, there!");
    

    // several ways
    $colorizer = new Colorizer;
    $colorizer = new Colorizer($config);
    $colorizer = Colorizer::config($config);

    $colorizer->config($config)
        ->echo("Hi, there!")
        ->echo(" How's it going with you?", PHP_EOL);
    

    Colorizer::attributes(['underline', 'strike'])
        ->echo("Hi, there!", PHP_EOL);
    

    Colorizer::foreground('green')
        ->echo("Hi, there!", PHP_EOL);
    

    Colorizer::foreground('#ffcc00')  // or #fc0
        ->echo("Hi, there!", PHP_EOL);
    

    Colorizer::foreground(2)
        ->echo("Hi, there!", PHP_EOL);
    

    Colorizer::foreground([0, 255, 0])
        ->echo("Hi, there!", PHP_EOL);
    

    Colorizer::background("red")
        ->echo("Hi, there!", PHP_EOL);
    

    Colorizer::background("#ffcc00")  // or #fc0
        ->echo("Hi, there!", PHP_EOL);
    

    Colorizer::background(1)
        ->echo("Hi, there!", PHP_EOL);
    

    Colorizer::background([255, 0, 0])
        ->echo("Hi, there!", PHP_EOL);
    

    Colorizer::attributes(['double-underline', 'italic'])
        ->foreground("yellow")
        ->background("blue")
        ->echo("Hi, there!", PHP_EOL);
    

    Colorizer::underline("#ffcc00")  // or #fc0
        ->echo("Hi, there!", PHP_EOL);
    

    Colorizer::underline(1)
        ->echo("Hi, there!", PHP_EOL);
    

    Colorizer::underline([255, 0, 0])
        ->echo("Hi, there!", PHP_EOL);
    

    echo Colorizer::config($config)
        ->encode("Hi, there!") . PHP_EOL;
    

    echo sprintf(
        "%s: %s%s",
        $name,
        Colorizer::config($config)
            ->encode("Hi, there!"),
        PHP_EOL
    );
    

    echo Colorizer::attributes(["bold"])
        ->background([255, 255, 0])
        ->foreground([0, 128, 255])
        ->readable('Hi, There!', PHP_EOL);