PHP Classes

File: docs/Trim.md

Recommend this page to a friend!
  Classes of jawira   PHP Sanitize Object   docs/Trim.md   Download  
File: docs/Trim.md
Role: Auxiliary data
Content type: text/markdown
Description: Auxiliary data
Class: PHP Sanitize Object
Process class variables with rules from comments
Author: By
Last change:
Date: 11 months ago
Size: 1,172 bytes
 

Contents

Class file image Download

Trim

Strip whitespace (or other characters) from the beginning and end of a string.

Trim only works with string, any other type is ignored.

Parameters

<dl> <dt>characters:</dt> <dd>Set of characters you want to remove, default value is "<code> \t\n\r\0\x0B</code>".</dd> <dt>direction:</dt> <dd> Use <code>both</code> to apply trim at the beginning and the end of string, this is the default value.<br> Use <code>left</code> to apply trim at the beginning of string.<br> Use <code>right</code> to apply trim at the end of string. </dd> </dl>

Examples

Remove spaces from the beggining and end of string:

use Jawira\Sanitizer\Filters as Sanitizer;

class User {
    #[Sanitizer\Trim]
    private string $name;
}

Remove spaces at the end of the string:

use Jawira\Sanitizer\Filters as Sanitizer;

class User {
    #[Sanitizer\Trim(side: 'right')]
    private string $name;
}

Remove periods, commas and tabulations at the beginning of the string:

use Jawira\Sanitizer\Filters as Sanitizer;

class User {
    #[Sanitizer\Trim(side: 'left', characters: ".,\t")]
    private string $name;
}

See also

Pad