class Str (View source)

Traits

Properties

static protected array $macros

The registered string macros.

from  MacroableTrait
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 void
macro(string $name, callable $macro)

Register a custom macro.

static bool
hasMacro(string $name)

Checks if macro is registered

static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

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
plural(string $value, int $count = 2)

Get the plural form of an English word.

static string
random(int $length = 16)

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

static string
quickRandom(int $length = 16)

Generate a "random" alpha-numeric 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
singular(string $value)

Get the singular form of an English word.

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.

Details

static void macro(string $name, callable $macro)

Register a custom macro.

Parameters

string $name
callable $macro

Return Value

void

static bool hasMacro(string $name)

Checks if macro is registered

Parameters

string $name

Return Value

bool

static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

static string ascii(string $value)

Transliterate a UTF-8 value to ASCII.

Parameters

string $value

Return Value

string

static string camel(string $value)

Convert a value to camel case.

Parameters

string $value

Return Value

string

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

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

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

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

Determine if a given string matches a given pattern.

Parameters

string $pattern
string $value

Return Value

bool

static int length(string $value)

Return the length of the given string.

Parameters

string $value

Return Value

int

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

static string lower(string $value)

Convert the given string to lower-case.

Parameters

string $value

Return Value

string

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

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

static string plural(string $value, int $count = 2)

Get the plural form of an English word.

Parameters

string $value
int $count

Return Value

string

static string random(int $length = 16)

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

Parameters

int $length

Return Value

string

Exceptions

RuntimeException

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

static string upper(string $value)

Convert the given string to upper-case.

Parameters

string $value

Return Value

string

static string title(string $value)

Convert the given string to title case.

Parameters

string $value

Return Value

string

static string singular(string $value)

Get the singular form of an English word.

Parameters

string $value

Return Value

string

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

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

Parameters

string $title
string $separator

Return Value

string

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

Convert a string to snake case.

Parameters

string $value
string $delimiter

Return Value

string

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

static string studly(string $value)

Convert a value to studly caps case.

Parameters

string $value

Return Value

string