Text
in package
Text processing static class Mostly just helpers
Table of Contents
- generateToken() : string
- Generate a relatively random token of a given length.
- isUuid() : bool
- Determine if passed string is a UUIDv4
- parseSrn() : array<string|int, mixed>
- Parse SRN into component parts Return array in the format of <ul> <li>client</li> <li>appid</li> <li>resource</li> <li>uuid</li> <li>extra</li> </ul>
- Pluralize() : string
- pluralize a word
- singularize() : string
- Singularize a word
- sluggify() : string
- Generate slugs
- truncate() : string
- Trim a string, optionally preserving the sentences.
- uuid() : string
- Generate a (hopefully) unique, time-based UUID
- without() : string
- Return string with filtered text removed
Methods
generateToken()
Generate a relatively random token of a given length.
public
static generateToken([int $length = 10 ]) : string
THIS IS NOT CRYPTOGRAPHICALY SECURE and don't use it for that purpose. You're going to have a bad time.
Based on (https://stackoverflow.com/a/1516430) but improved for randomness and security.
Parameters
- $length : int = 10
Return values
string —isUuid()
Determine if passed string is a UUIDv4
public
static isUuid(string $str) : bool
Parameters
- $str : string
Return values
bool —parseSrn()
Parse SRN into component parts Return array in the format of <ul> <li>client</li> <li>appid</li> <li>resource</li> <li>uuid</li> <li>extra</li> </ul>
public
static parseSrn(string $srn) : array<string|int, mixed>
Parameters
- $srn : string
Return values
array<string|int, mixed> —Pluralize()
pluralize a word
public
static Pluralize(mixed $str) : string
Parameters
- $str : mixed
Return values
string —singularize()
Singularize a word
public
static singularize(mixed $str) : string
Parameters
- $str : mixed
Return values
string —sluggify()
Generate slugs
public
static sluggify(string $str[, mixed $delim = '-' ]) : string
Parameters
- $str : string
-
string to sluggify
- $delim : mixed = '-'
Tags
Return values
string —slugged string
truncate()
Trim a string, optionally preserving the sentences.
public
static truncate(string $str[, string $length = 100 ][, string $ending = '...' ][, bool $exact = false ][, bool $considerHtml = true ]) : string
Parameters
- $str : string
- $length : string = 100
-
Trim length
- $ending : string = '...'
-
String end
- $exact : bool = false
-
Make resulting string the exact length
- $considerHtml : bool = true
-
Consider the HTML output when trimming
Return values
string —uuid()
Generate a (hopefully) unique, time-based UUID
public
static uuid() : string
Return values
string —UUID
without()
Return string with filtered text removed
public
static without(mixed $str[, mixed $filter = '' ]) : string
Parameters
- $str : mixed
- $filter : mixed = ''