RdbaString
in package
String class. (String class name is reserved, see https://www.php.net/manual/en/reserved.other-reserved-words.php for more details.)
Tags
Table of Contents
Methods
- __callStatic() : mixed
- For static methods on non-static methods.
- filterSanitizeString() : string
- Strip HTML tags and then do the `htmlspecialchars()` with single quotes.
- random() : string
- Generate random string.
- randomUnicode() : string
- Generate random unicode string.
- sanitizeDisplayname() : string
- Sanitize display name.
- sanitizeUsername() : string
- Sanitize username.
- staticFilterSanitizeString() : static
- staticRandom() : static
- staticRandomUnicode() : static
- staticSanitizeDisplayname() : static
- staticSanitizeUsername() : static
Methods
__callStatic()
For static methods on non-static methods.
public
static __callStatic(string $name, array<string|int, mixed> $arguments) : mixed
Parameters
- $name : string
-
The method name.
- $arguments : array<string|int, mixed>
-
The method's arguments.
Tags
filterSanitizeString()
Strip HTML tags and then do the `htmlspecialchars()` with single quotes.
public
filterSanitizeString(string $string) : string
This is for replacement that FILTER_SANITIZE_STRING
constant has been deprecated since PHP 8.1
This method does not support any flags that FILTER_SANITIZE_STRING
constant may have.
Parameters
- $string : string
-
The string to be filter and sanitize.
Tags
Return values
string —Return filtered and sanitized string.
random()
Generate random string.
public
random([int $length = 10 ][, string $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' ]) : string
For ASCII text only.
Parameters
- $length : int = 10
-
String length.
- $characters : string = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
-
The allowed characters.
Tags
Return values
string —Return generated random string.
randomUnicode()
Generate random unicode string.
public
randomUnicode([int $length = 10 ][, string $characters = '' ]) : string
To count the length, please use mb_strlen()
instead of strlen()
.
Parameters
- $length : int = 10
-
String length.
- $characters : string = ''
-
The allowed characters.
Tags
Return values
string —Return generated random string.
sanitizeDisplayname()
Sanitize display name.
public
sanitizeDisplayname(string $displayname) : string
The difference from sanitizeUsername()
as it will not remove space between text but allowed just one.
Parameters
- $displayname : string
-
The display name.
Tags
Return values
string —Return sanitized display name.
sanitizeUsername()
Sanitize username.
public
sanitizeUsername(string $username) : string
Parameters
- $username : string
-
The input username.
Tags
Return values
string —Return sanitized username.
staticFilterSanitizeString()
public
staticFilterSanitizeString([string $paramName = ]) : static
Parameters
- $paramName : string =
Return values
staticstaticRandom()
public
staticRandom([int $length = ][, string $characters = ]) : static
Parameters
- $length : int =
- $characters : string =
Return values
staticstaticRandomUnicode()
public
staticRandomUnicode([int $length = ][, string $characters = ]) : static
Parameters
- $length : int =
- $characters : string =
Return values
staticstaticSanitizeDisplayname()
public
staticSanitizeDisplayname([string $displayname = ]) : static
Parameters
- $displayname : string =
Return values
staticstaticSanitizeUsername()
public
staticSanitizeUsername([string $username = ]) : static
Parameters
- $username : string =