PHP code example of andydune / custom-string-explode

1. Go to this page and download the library: Download andydune/custom-string-explode 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/ */

    

andydune / custom-string-explode example snippets


use AndyDune\CustomStringExplode\Rule\Numbers;
use AndyDune\CustomStringExplode\StringContainer;

$numbers = new Numbers();
$explode = new StringContainer($numbers);
$results = $explode->explode('123 13-4 00');

// Result is
$result = [123, 13, 4, 00];


use AndyDune\CustomStringExplode\Rule\Email;
use AndyDune\CustomStringExplode\StringContainer;

$rule = new Email();
$explode = new StringContainer($rule);

$results = $explode->explode('Андрей Рыжов,  ;
Andrey Ryzhov,
[email protected] ,
[email protected]
[email protected]
#!$%&\'*+-/=?^_`{}|[email protected]
"()<>[]:,;@\\\"!#$%&\'-/=?^_`{}| ~.a"@example.org
');

// Result is
$result = [
    '[email protected]', 
    '[email protected]', 
    '[email protected]', 
    '#!$%&'*+-/=?^_`{}|[email protected]'
];


use AndyDune\CustomStringExplode\StringContainer;
use AndyDune\CustomStringExplode\Rule\NumbersAndLatinLetters;

$rule = new NumbersAndLatinLetters();
$explode = new StringContainer($rule);

$results = $explode->explode('adqwdqw123 adasdsa;78
првиетhellow
');

// Result is
$result = [
    'adqwdqw123', 
    'adasdsa', 
    '78', 
    'hellow'
];

use AndyDune\CustomStringExplode\Rule\DelimiterWhitespaceCharacter;
use AndyDune\CustomStringExplode\StringContainer;
$rule = new DelimiterWhitespaceCharacter();
$explode = new StringContainer($rule);

$results = $explode->explode('123 13-4 00');

// Result is
$result = [
    '123', 
    '13-4', 
    '00' 
];

namespace AndyDune\CustomStringExplode\Rule;
use AndyDune\CustomStringExplode\StringContainer;

abstract class RuleAbstract
{
    /**
     * @var StringContainer
     */
    protected $container;

    /**
     * @return StringContainer
     */
    public function getContainer()
    {
        return $this->container;
    }

    /**
     * @param StringContainer $container
     */
    public function setContainer($container)
    {
        $this->container = $container;
    }

    public function format($string)
    {
        return trim($string);
    }

    /**
    * @params string $char current char for check
    * @params string $item previously collected char
    * @params array $array array was colected during previous executions of method
    */
    abstract public function check($char, $item, $array);
}

php composer.phar 

php composer.phar update