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;

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

Trimmer::ltrim(' trimmer ');               // "trimmer "
Trimmer::ltrim(' @trimmer@ ', "\x20\x40"); // "trimmer@ "

Trimmer::rtrim(' trimmer ');               // " trimmer"
Trimmer::rtrim(' @trimmer@ ', "\x20\x40"); // " @trimmer"

Trimmer::trim([' trimmerA ']);
// => ["trimmerA"]

Trimmer::trim([' trimmerA ', [' trimmerB ']]);
// => ["trimmerA", ["trimmerB"]]

Trimmer::trim([' trimmerA ', 1, 1.0, true, null]);
// => ["trimmerA", 1, 1.0, true, null]

Trimmer::trim([' trimmerA ', [' trimmerB ', 1, 1.0, true, null]]);
// => ["trimmerA", ["trimmerB", 1, 1.0, true, null]]

$objectA = new class {
    private string $propertyA = ' trimmerA ';
    private string $propertyB = ' trimmerB '; // This 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, $propertyB will remain unchanged.

$objectB = new class($objectA) {
    private string $propertyC = ' trimmerC ';
    private string $propertyD = ' trimmerD '; // This 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, $propertyD and $objectA->$propertyB will remain unchanged.