PHP code example of bvp / trimmer

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

    

bvp / trimmer example snippets




VP\Trimmer\Trimmer;

// Trim strings
echo Trimmer::trim(' trimmer ');                // "trimmer"
echo Trimmer::trim(' @trimmer@ ', "\x20\x40");  // "trimmer"

// Left-side trim only
echo Trimmer::ltrim(' trimmer ');               // "trimmer "
echo Trimmer::ltrim(' @trimmer@ ', "\x20\x40"); // "trimmer@ "

// Right-side trim only
echo Trimmer::rtrim(' trimmer ');               // " trimmer"
echo Trimmer::rtrim(' @trimmer@ ', "\x20\x40"); // " @trimmer"

$result = Trimmer::trim([' trimmerA ']);
print_r($result);

// Output:
Array
(
    [0] => trimmerA
)

$result = Trimmer::trim([' trimmerA ', [' trimmerB ']]);
print_r($result);

// Output:
Array
(
    [0] => trimmerA
    [1] => Array
        (
            [0] => trimmerB
        )
)

$result = Trimmer::trim([' trimmerA ', 1, 1.0, true, null]);
print_r($result);

// Output:
Array
(
    [0] => trimmerA
    [1] => 1
    [2] => 1
    [3] => 1
    [4] =>
)

$objectA = new class {
    private string $propertyA = ' trimmerA ';
    private string $propertyB = ' trimmerB '; // Will NOT be trimmed
    public function getPropertyA(): string { return $this->propertyA; }
    public function setPropertyA(string $value): void { $this->propertyA = $value; }
    public function getPropertyB(): string { return $this->propertyB; }
};

Trimmer::trim($objectA);

// $propertyA will be trimmed, but $propertyB remains unchanged

$objectB = new class($objectA) {
    private string $propertyC = ' trimmerC ';
    private string $propertyD = ' trimmerD '; // Will NOT be trimmed
    private object $objectA;
    public function __construct(object $objectA) {
        $this->objectA = $objectA;
    }
    public function getPropertyC(): string { return $this->propertyC; }
    public function setPropertyC(string $value): void { $this->propertyC = $value; }
    public function getPropertyD(): string { return $this->propertyD; }
    public function getObjectA(): object { return $this->objectA; }
};

Trimmer::trim($objectB);

// $propertyC and $objectA->propertyA will be trimmed,
// but $propertyD and $objectA->propertyB remain unchanged