PHP code example of flsouto / pipe

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

    

flsouto / pipe example snippets



use FlSouto\Pipe;

$pipe = new Pipe();
$pipe->add('trim')->add(function($value){
	return str_replace(['4','1','0'],['a','i','o'],$value);
});

$result = $pipe->run(' f4b10 ');

echo $result->output;

use FlSouto\Pipe;

$pipe = new Pipe();
$pipe->add(function($value){
	if(strstr($value,'4')){
		echo 'The value cannot contain the number 4.';
	}
});
$result = $pipe->run('f4b10');

echo $result->error;


$pipe = new Pipe();
$pipe->add(function($value){
	return str_replace('4','a',$value);
});
$pipe->add(function($value){
	if(strstr($value,'4')){
		echo 'The value cannot contain the number 4.';
	}
});
$result = $pipe->run('f4b10');



$pipe = new Pipe();
$pipe->add(function($v){
    iF(preg_match("/\d/",$v)){
        echo "The value cannot contain digits.";
    }
});

$result = $pipe->run($input="My name is 12345");

echo $result->output;


$pipe = new Pipe();
$pipe->fallback('default');
   $pipe->add(function($v){
       iF(preg_match("/\d/",$v)){
           echo "The value cannot contain digits.";
       }
   });
$result = $pipe->run('My name is 12345');

echo $result->output;


$pipe = new Pipe();
$pipe->fallback('default');
$result = $pipe->run(null);

echo $result->output;


$pipe = new Pipe();
$pipe->fallback('default');
$result = $pipe->run('');

var_dump($result->output);


$pipe = new Pipe();
$pipe->fallback('default',[null,'',0]);
$result = $pipe->run('');

echo $result->output;


  	$pipe = Pipe::create([
  		'trim',
  		function($value){ return str_replace('_','/',$value); }
  	]);