Ascii

Ascii - Remove all characters except ascii characters.

In practice this means that all characters with a numerical value greater than 127 are removed.

Ascii sanitizer only works with string, any other type is ignored.

Basic usage

use Jawira\Sanitizer\Filters as Sanitizer;

class User {
  #[Sanitizer\Ascii]
  public string $username;
}

Parameters

bool onlyPrintable (optional):
Default value is false, all ascii characters are preserved.
When true all characters with numerical value less than 32 are also removed, this is the first column of the following table.

Ascii table

Examples

Remove all non-ascii characters:

use Jawira\Sanitizer\Filters as Sanitizer;

class Message {
  #[Sanitizer\Ascii]
  public string $content;
}
"Único"    → "nico"
"Γεια σας" → " "
"Foo\nBar" → "Foo\nBar"
"\tHello"  → "\tHello"

Remove all non-ascii characters and removing non-printable characters:

use Jawira\Sanitizer\Filters as Sanitizer;

class Message {
  #[Sanitizer\Ascii(onlyPrintable: true)]
  public string $content;
}
"Único"    → "nico"
"Γεια σας" → " "
"Foo\nBar" → "FooBar"
"\tHello"  → "Hello"

See also

-