SanitizeFlag uses BitFlagTrait
Enumeration representing string sanitization modes as bit flags.
Each flag can be combined using the bitwise OR operator (|) to form a mask.
The has() helper can be used to check if a particular flag is present in a mask.
Tags
Table of Contents
Constants
- ALL = self::TRIM | self::NULLIFY | self::NORMALIZE_LINE_BREAKS | self::REMOVE_EXTRA_LINE_BREAKS | self::REMOVE_INVISIBLE | self::COLLAPSE_SPACES | self::STRIP_TAGS | self::DECODE_ENTITIES | self::REMOVE_CONTROL_CHARS | self::NORMALIZE_UNICODE
- All flags combined.
- CLEAN_HTML = self::TRIM | self::STRIP_TAGS | self::DECODE_ENTITIES | self::COLLAPSE_SPACES
- Clean HTML flags (for user-submitted HTML content)
- COLLAPSE_SPACES = 1 << 5
- Collapse multiple spaces into one
- DECODE_ENTITIES = 1 << 7
- Decode HTML entities to their corresponding characters.
- DEFAULT = self::TRIM | self::REMOVE_INVISIBLE
- Default flags
- FLAGS = [self::TRIM, self::NULLIFY, self::NORMALIZE_LINE_BREAKS, self::REMOVE_EXTRA_LINE_BREAKS, self::REMOVE_INVISIBLE, self::COLLAPSE_SPACES, self::STRIP_TAGS, self::DECODE_ENTITIES, self::REMOVE_CONTROL_CHARS, self::NORMALIZE_UNICODE]
- List of all flags
- FLAGS_NAME = [self::TRIM => 'TRIM', self::NULLIFY => 'NULLIFY', self::NORMALIZE_LINE_BREAKS => 'NORMALIZE_LINE_BREAKS', self::REMOVE_EXTRA_LINE_BREAKS => 'REMOVE_EXTRA_LINE_BREAKS', self::REMOVE_INVISIBLE => 'REMOVE_INVISIBLE', self::COLLAPSE_SPACES => 'COLLAPSE_SPACES', self::STRIP_TAGS => 'STRIP_TAGS', self::DECODE_ENTITIES => 'DECODE_ENTITIES', self::REMOVE_CONTROL_CHARS => 'REMOVE_CONTROL_CHARS', self::NORMALIZE_UNICODE => 'NORMALIZE_UNICODE']
- Names of flags
- NONE = 0
- Do nothing.
- NORMALIZE = self::TRIM | self::REMOVE_INVISIBLE | self::NORMALIZE_LINE_BREAKS | self::NORMALIZE_UNICODE
- Normalize flags (for consistent text processing)
- NORMALIZE_LINE_BREAKS = 1 << 2
- Normalize line breaks (\r\n, \r → \n)
- NORMALIZE_UNICODE = 1 << 9
- Normalize Unicode characters (NFD, NFC, NFKD, NFKC).
- NULLIFY = 1 << 1
- Convert empty string to null
- REMOVE_CONTROL_CHARS = 1 << 8
- Remove all non-printable ASCII characters (0x00-0x1F, 0x7F).
- REMOVE_EXTRA_LINE_BREAKS = 1 << 3
- Collapse multiple consecutive line breaks into one.
- REMOVE_INVISIBLE = 1 << 4
- Remove invisible Unicode characters (zero-width, non-breaking, etc.)
- STRICT = self::TRIM | self::NULLIFY | self::REMOVE_INVISIBLE | self::REMOVE_CONTROL_CHARS | self::NORMALIZE_LINE_BREAKS | self::REMOVE_EXTRA_LINE_BREAKS | self::COLLAPSE_SPACES
- Strict flags (aggressive cleaning)
- STRIP_TAGS = 1 << 6
- Remove HTML/PHP tags
- TRIM = 1 << 0
- Trim spaces, tabs, and line breaks at the start and end
Methods
- describe() : string
- Gets a human-readable description of the flags in a bitmask.
- getFlags() : array<string|int, int>
- Gets a list of all individual flags present in a bitmask.
- has() : bool
- Checks whether a specific flag is set in a bitmask.
- isValid() : bool
- Validates that a bitmask contains only valid flags.
Constants
ALL
All flags combined.
public
mixed
ALL
= self::TRIM | self::NULLIFY | self::NORMALIZE_LINE_BREAKS | self::REMOVE_EXTRA_LINE_BREAKS | self::REMOVE_INVISIBLE | self::COLLAPSE_SPACES | self::STRIP_TAGS | self::DECODE_ENTITIES | self::REMOVE_CONTROL_CHARS | self::NORMALIZE_UNICODE
CLEAN_HTML
Clean HTML flags (for user-submitted HTML content)
public
mixed
CLEAN_HTML
= self::TRIM | self::STRIP_TAGS | self::DECODE_ENTITIES | self::COLLAPSE_SPACES
COLLAPSE_SPACES
Collapse multiple spaces into one
public
mixed
COLLAPSE_SPACES
= 1 << 5
DECODE_ENTITIES
Decode HTML entities to their corresponding characters.
public
mixed
DECODE_ENTITIES
= 1 << 7
Example: & → &, < → <, " → "
DEFAULT
Default flags
public
mixed
DEFAULT
= self::TRIM | self::REMOVE_INVISIBLE
FLAGS
List of all flags
public
mixed
FLAGS
= [self::TRIM, self::NULLIFY, self::NORMALIZE_LINE_BREAKS, self::REMOVE_EXTRA_LINE_BREAKS, self::REMOVE_INVISIBLE, self::COLLAPSE_SPACES, self::STRIP_TAGS, self::DECODE_ENTITIES, self::REMOVE_CONTROL_CHARS, self::NORMALIZE_UNICODE]
FLAGS_NAME
Names of flags
public
mixed
FLAGS_NAME
= [self::TRIM => 'TRIM', self::NULLIFY => 'NULLIFY', self::NORMALIZE_LINE_BREAKS => 'NORMALIZE_LINE_BREAKS', self::REMOVE_EXTRA_LINE_BREAKS => 'REMOVE_EXTRA_LINE_BREAKS', self::REMOVE_INVISIBLE => 'REMOVE_INVISIBLE', self::COLLAPSE_SPACES => 'COLLAPSE_SPACES', self::STRIP_TAGS => 'STRIP_TAGS', self::DECODE_ENTITIES => 'DECODE_ENTITIES', self::REMOVE_CONTROL_CHARS => 'REMOVE_CONTROL_CHARS', self::NORMALIZE_UNICODE => 'NORMALIZE_UNICODE']
NONE
Do nothing.
public
int
NONE
= 0
NORMALIZE
Normalize flags (for consistent text processing)
public
mixed
NORMALIZE
= self::TRIM | self::REMOVE_INVISIBLE | self::NORMALIZE_LINE_BREAKS | self::NORMALIZE_UNICODE
NORMALIZE_LINE_BREAKS
Normalize line breaks (\r\n, \r → \n)
public
mixed
NORMALIZE_LINE_BREAKS
= 1 << 2
NORMALIZE_UNICODE
Normalize Unicode characters (NFD, NFC, NFKD, NFKC).
public
mixed
NORMALIZE_UNICODE
= 1 << 9
Uses 'NFC' normalization by default (canonical decomposition + composition).
NULLIFY
Convert empty string to null
public
mixed
NULLIFY
= 1 << 1
REMOVE_CONTROL_CHARS
Remove all non-printable ASCII characters (0x00-0x1F, 0x7F).
public
mixed
REMOVE_CONTROL_CHARS
= 1 << 8
Less aggressive than REMOVE_INVISIBLE, keeps Unicode characters.
REMOVE_EXTRA_LINE_BREAKS
Collapse multiple consecutive line breaks into one.
public
mixed
REMOVE_EXTRA_LINE_BREAKS
= 1 << 3
REMOVE_INVISIBLE
Remove invisible Unicode characters (zero-width, non-breaking, etc.)
public
mixed
REMOVE_INVISIBLE
= 1 << 4
STRICT
Strict flags (aggressive cleaning)
public
mixed
STRICT
= self::TRIM | self::NULLIFY | self::REMOVE_INVISIBLE | self::REMOVE_CONTROL_CHARS | self::NORMALIZE_LINE_BREAKS | self::REMOVE_EXTRA_LINE_BREAKS | self::COLLAPSE_SPACES
STRIP_TAGS
Remove HTML/PHP tags
public
mixed
STRIP_TAGS
= 1 << 6
TRIM
Trim spaces, tabs, and line breaks at the start and end
public
mixed
TRIM
= 1 << 0
Methods
describe()
Gets a human-readable description of the flags in a bitmask.
public
static describe(int $mask[, string $separator = ', ' ]) : string
Parameters
- $mask : int
- $separator : string = ', '
Return values
stringgetFlags()
Gets a list of all individual flags present in a bitmask.
public
static getFlags(int $mask) : array<string|int, int>
Parameters
- $mask : int
Return values
array<string|int, int>has()
Checks whether a specific flag is set in a bitmask.
public
static has(int $mask, int $flag) : bool
Parameters
- $mask : int
- $flag : int
Return values
boolisValid()
Validates that a bitmask contains only valid flags.
public
static isValid(int $mask) : bool
Parameters
- $mask : int