DataStructureString
String Data Structure helper
Provides utility methods to assist in manipulating strings.
Attributes
- #[AllowDynamicProperties]
Table of Contents
Methods
| htmlToText() | Converts the HTML given to text |
| random() | Generates a random string from a list of characters |
| removeFromText() | Removes the given $content from the provided $text |
| truncate() | Truncates the string using the given options |
Methods
htmlToText()
Converts the HTML given to text
public
htmlToText(string $html) : string
Parameters
- $html : string
-
The HTML string
Return values
string —The textual representation of the HTML
random()
Generates a random string from a list of characters
public
random([int $length = 8 ][, string $pool = null ][, array<string|int, mixed> $options = [] ]) : string
Parameters
- $length : int = 8
-
The length of the random string
- $pool : string = null
-
The pool of characters to include in the random string, defaults to alpha numeric characters. Can be configured further in $options['types']
- $options : array<string|int, mixed> = []
-
An array of options including:
- types A numerically indexed-array of character-types that may be used to generate the random string (i.e. "alpha", "alpha_lower", "alpha_upper", and/or "numeric") (optional)
Return values
string —A randomly generated word with the given length
removeFromText()
Removes the given $content from the provided $text
public
removeFromText(string $text, string|array<string|int, mixed> $content) : string
Parameters
- $text : string
-
The full text string
- $content : string|array<string|int, mixed>
-
A string value, or numerically-indexed array of strings, representing exact textual matches from which to remove from $text
Return values
string —The provided $text with specific $content removed
truncate()
Truncates the string using the given options
public
truncate(string $input[, array<string|int, mixed> $options = [] ]) : mixed
Parameters
- $input : string
-
The input string to truncate
- $options : array<string|int, mixed> = []
-
A list of options including any of the following:
- length The number of characters to truncate to - NOT multi-byte-safe (optional, default null)
- word_length The number of words to truncate to, broken at spaces (optional, default null)
- line_break True to truncate at the first new line, or false to allow new line breaks (optional, default true)