XString
in package
Provides various helper methods for strings.
Table of Contents
Constants
- RANDOM_CHARS = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789'
- Default character set for the random method.
Methods
- countUnique() : int
- Counts unique characters in a string.
- escape() : string
- Converts special characters to HTML entities.
- nullOrEmpty() : bool
- Check if a string is null or empty.
- nullOrWhitespace() : bool
- Check if a string is null or whitespace.
- random() : string
- Generates a random string of user specified length.
Constants
RANDOM_CHARS
Default character set for the random method.
public
string
RANDOM_CHARS
= 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789'
Methods
countUnique()
Counts unique characters in a string.
public
static countUnique(Stringable|string $string) : int
Parameters
- $string : Stringable|string
-
String to count unique characters of.
Return values
int —Unique character count.
escape()
Converts special characters to HTML entities.
public
static escape(Stringable|string $string[, int $flags = ENT_COMPAT | ENT_HTML5 ][, string|null $encoding = null ][, bool $doubleEncoding = true ]) : string
Uses htmlspecialchars with alternate defaults.
Parameters
- $string : Stringable|string
-
The string being converted.
- $flags : int = ENT_COMPAT | ENT_HTML5
-
A bitmask consisting of flags found in the documentation for htmlspecialchars.
- $encoding : string|null = null
-
Optional argument defining the encoding used when converting characters.
- $doubleEncoding : bool = true
-
Also reencode existing HTML entities.
Return values
string —The converted string.
nullOrEmpty()
Check if a string is null or empty.
public
static nullOrEmpty(Stringable|string|null $string) : bool
Parameters
- $string : Stringable|string|null
-
String ot check for emptiness.
Return values
bool —true if the string is empty, false if not.
nullOrWhitespace()
Check if a string is null or whitespace.
public
static nullOrWhitespace(Stringable|string|null $string) : bool
Parameters
- $string : Stringable|string|null
-
String to check for whitespace.
Return values
bool —true if the string is whitespace, false if not.
random()
Generates a random string of user specified length.
public
static random(int $length[, string $chars = self::RANDOM_CHARS ]) : string
Parameters
- $length : int
-
Desired length of the string.
- $chars : string = self::RANDOM_CHARS
-
Set of characters to pick from. Default set contains the alphabet in upper- and lowercase and numbers 0 thru 9.
Return values
string —The generated string.