PHP code example of burnett01 / php-piper

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

    

burnett01 / php-piper example snippets


$nonce = random_bytes(16)
      |> base64_encode(...);       

// does not work
$nonce = random_bytes(16)
      |> base64_encode(...)
      |> strtr(..., '+/', '-_')
      |> rtrim(..., '=');       

// works but too verbose
$nonce = random_bytes(16)
      |> base64_encode(...)
      |> (fn(string $s): string => strtr($s, '+/', '-_'))
      |> (fn($s) => rtrim($s, '='));    

use function Burnett01\Piper\with;

$nonce = random_bytes(16)
      |> base64_encode(...)
      |> with('strtr', '+/', '-_')
      // first-class syntax
      |> with(rtrim(...), '=');

// or pipe() function

use function Burnett01\Piper\pipe;

$nonce = random_bytes(16)
      |> base64_encode(...)
      |> pipe('strtr', '+/', '-_')
      // with first-class syntax
      |> pipe(rtrim(...), '=');

use Burnett01\Piper\Piper as pipe;

$nonce = random_bytes(16)
      |> base64_encode(...)
      |> pipe::to('strtr', '+/', '-_')
      // or 'with' + first-class syntax
      |> pipe::with(rtrim(...), '=');       

use function Burnett01\Piper\with;

$actual = -1234.5
      |> abs(...)
      |> with(number_format(...), 2, '.', ',')
      |> urlencode(...);