class Str

Properties

static protected array $snakeCache The cache of snake-cased words.
static protected array $camelCache The cache of camel-cased words.
static protected array $studlyCache The cache of studly-cased words.

Methods

static string
ascii(string $value)

Transliterate a UTF-8 value to ASCII.

static string
camel(string $value)

Convert a value to camel case.

static bool
contains(string $haystack, string|array $needles)

Determine if a given string contains a given substring.

static bool
endsWith(string $haystack, string|array $needles)

Determine if a given string ends with a given substring.

static string
finish(string $value, string $cap)

Cap a string with a single instance of a given value.

static bool
is(string $pattern, string $value)

Determine if a given string matches a given pattern.

static int
length(string $value)

Return the length of the given string.

static string
limit(string $value, int $limit = 100, string $end = '...')

Limit the number of characters in a string.

static string
lower(string $value)

Convert the given string to lower-case.

static string
words(string $value, int $words = 100, string $end = '...')

Limit the number of words in a string.

static array
parseCallback(string $callback, string $default = "")

Parse a "Class@method" style callback into class and method.

static string
random(int $length = 16)

Generate a more truly "random" alpha-numeric string.

static string
randomBytes(int $length = 16) deprecated

Generate a more truly "random" bytes.

static string
quickRandom(int $length = 16)

Generate a "random" alpha-numeric string.

static bool
equals(string $knownString, string $userInput) deprecated

Compares two strings using a constant-time algorithm.

static string
replaceFirst(string $search, string $replace, string $subject)

Replace the first occurrence of a given value in the string.

static string
replaceLast(string $search, string $replace, string $subject)

Replace the last occurrence of a given value in the string.

static string
upper(string $value)

Convert the given string to upper-case.

static string
title(string $value)

Convert the given string to title case.

static string
slug(string $title, string $separator = '-')

Generate a URL friendly "slug" from a given string.

static string
snake(string $value, string $delimiter = '_')

Convert a string to snake case.

static bool
startsWith(string $haystack, string|array $needles)

Determine if a given string starts with a given substring.

static string
studly(string $value)

Convert a value to studly caps case.

static string
substr(string $string, int $start, int $length = null)

Returns the portion of string specified by the start and length parameters.

static string
ucfirst(string $string)

Make a string's first character uppercase.

static array
charsArray()

Returns the replacements for the ascii method.

Details

at line 39
static string ascii(string $value)

Transliterate a UTF-8 value to ASCII.

Parameters

string $value

Return Value

string

at line 54
static string camel(string $value)

Convert a value to camel case.

Parameters

string $value

Return Value

string

at line 70
static bool contains(string $haystack, string|array $needles)

Determine if a given string contains a given substring.

Parameters

string $haystack
string|array $needles

Return Value

bool

at line 88
static bool endsWith(string $haystack, string|array $needles)

Determine if a given string ends with a given substring.

Parameters

string $haystack
string|array $needles

Return Value

bool

at line 107
static string finish(string $value, string $cap)

Cap a string with a single instance of a given value.

Parameters

string $value
string $cap

Return Value

string

at line 121
static bool is(string $pattern, string $value)

Determine if a given string matches a given pattern.

Parameters

string $pattern
string $value

Return Value

bool

at line 143
static int length(string $value)

Return the length of the given string.

Parameters

string $value

Return Value

int

at line 156
static string limit(string $value, int $limit = 100, string $end = '...')

Limit the number of characters in a string.

Parameters

string $value
int $limit
string $end

Return Value

string

at line 171
static string lower(string $value)

Convert the given string to lower-case.

Parameters

string $value

Return Value

string

at line 184
static string words(string $value, int $words = 100, string $end = '...')

Limit the number of words in a string.

Parameters

string $value
int $words
string $end

Return Value

string

at line 202
static array parseCallback(string $callback, string $default = "")

Parse a "Class@method" style callback into class and method.

Parameters

string $callback
string $default

Return Value

array

at line 214
static string random(int $length = 16)

Generate a more truly "random" alpha-numeric string.

Parameters

int $length

Return Value

string

Exceptions

Exception

at line 238
static string randomBytes(int $length = 16) deprecated

deprecated since version 5.2. Use random_bytes instead.

Generate a more truly "random" bytes.

Parameters

int $length

Return Value

string

Exceptions

Exception

at line 251
static string quickRandom(int $length = 16)

Generate a "random" alpha-numeric string.

Should not be considered sufficient for cryptography, etc.

Parameters

int $length

Return Value

string

at line 271
static bool equals(string $knownString, string $userInput) deprecated

deprecated since version 5.2. Use hash_equals instead.

Compares two strings using a constant-time algorithm.

Note: This method will leak length information.

Note: Adapted from Symfony\Component\Security\Core\Util\StringUtils.

Parameters

string $knownString
string $userInput

Return Value

bool

at line 284
static string replaceFirst(string $search, string $replace, string $subject)

Replace the first occurrence of a given value in the string.

Parameters

string $search
string $replace
string $subject

Return Value

string

at line 303
static string replaceLast(string $search, string $replace, string $subject)

Replace the last occurrence of a given value in the string.

Parameters

string $search
string $replace
string $subject

Return Value

string

at line 320
static string upper(string $value)

Convert the given string to upper-case.

Parameters

string $value

Return Value

string

at line 331
static string title(string $value)

Convert the given string to title case.

Parameters

string $value

Return Value

string

at line 343
static string slug(string $title, string $separator = '-')

Generate a URL friendly "slug" from a given string.

Parameters

string $title
string $separator

Return Value

string

at line 368
static string snake(string $value, string $delimiter = '_')

Convert a string to snake case.

Parameters

string $value
string $delimiter

Return Value

string

at line 392
static bool startsWith(string $haystack, string|array $needles)

Determine if a given string starts with a given substring.

Parameters

string $haystack
string|array $needles

Return Value

bool

at line 409
static string studly(string $value)

Convert a value to studly caps case.

Parameters

string $value

Return Value

string

at line 430
static string substr(string $string, int $start, int $length = null)

Returns the portion of string specified by the start and length parameters.

Parameters

string $string
int $start
int $length

Return Value

string

at line 441
static string ucfirst(string $string)

Make a string's first character uppercase.

Parameters

string $string

Return Value

string

at line 455
static protected array charsArray()

Returns the replacements for the ascii method.

Note: Adapted from Stringy\Stringy.

Return Value

array

See also

https://github.com/danielstjules/Stringy/blob/2.3.1/LICENSE.txt