W3cubDocs

/Laravel 8

Str

class Str (View source)

Traits

Macroable

Properties

static protected array $macros The registered string macros. from Macroable
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.
static protected callable $uuidFactory The callback that should be used to generate UUIDs.

Methods

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

Register a custom macro.

from Macroable
static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

from Macroable
static bool hasMacro(string $name)

Checks if macro is registered.

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

Dynamically handle calls to the class.

from Macroable
mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

from Macroable
static Stringable of(string $string)

Get a new stringable object from the given string.

static string after(string $subject, string $search)

Return the remainder of a string after the first occurrence of a given value.

static string afterLast(string $subject, string $search)

Return the remainder of a string after the last occurrence of a given value.

static string ascii(string $value, string $language = 'en')

Transliterate a UTF-8 value to ASCII.

static string before(string $subject, string $search)

Get the portion of a string before the first occurrence of a given value.

static string beforeLast(string $subject, string $search)

Get the portion of a string before the last occurrence of a given value.

static string between(string $subject, string $from, string $to)

Get the portion of a string between two given values.

static string camel(string $value)

Convert a value to camel case.

static bool contains(string $haystack, string|string[] $needles)

Determine if a given string contains a given substring.

static bool containsAll(string $haystack, array $needles)

Determine if a given string contains all array values.

static bool endsWith(string $haystack, string|string[] $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|array $pattern, string $value)

Determine if a given string matches a given pattern.

static bool isAscii(string $value)

Determine if a given string is 7 bit ASCII.

static bool isUuid(string $value)

Determine if a given string is a valid UUID.

static string kebab(string $value)

Convert a string to kebab case.

static int length(string $value, string|null $encoding = null)

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 string padBoth(string $value, int $length, string $pad = ' ')

Pad both sides of a string with another.

static string padLeft(string $value, int $length, string $pad = ' ')

Pad the left side of a string with another.

static string padRight(string $value, int $length, string $pad = ' ')

Pad the right side of a string with another.

static array<int,string|null> parseCallback(string $callback, string|null $default = null)

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

Pluralize the last word of an English, studly caps case string.

static string random(int $length = 16)

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

static string replaceArray(string $search, array $replace, string $subject)

Replace a given value in the string sequentially with an array.

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 start(string $value, string $prefix)

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

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 = '-', string|null $language = 'en')

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|string[] $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|null $length = null)

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

static int substrCount(string $haystack, string $needle, int $offset = 0, int|null $length = null)

Returns the number of substring occurrences.

static string ucfirst(string $string)

Make a string's first character uppercase.

static UuidInterface uuid()

Generate a UUID (version 4).

static UuidInterface orderedUuid()

Generate a time-ordered UUID (version 4).

static void createUuidsUsing(callable $factory = null)

Set the callable that will be used to generate UUIDs.

static void createUuidsNormally()

Indicate that UUIDs should be created normally and not using a custom factory.

Details

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

Register a custom macro.

Parameters

string $name
object|callable $macro

Return Value

void

static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

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 Stringable of(string $string)

Get a new stringable object from the given string.

Parameters

string $string

Return Value

Stringable

static string after(string $subject, string $search)

Return the remainder of a string after the first occurrence of a given value.

Parameters

string $subject
string $search

Return Value

string

static string afterLast(string $subject, string $search)

Return the remainder of a string after the last occurrence of a given value.

Parameters

string $subject
string $search

Return Value

string

static string ascii(string $value, string $language = 'en')

Transliterate a UTF-8 value to ASCII.

Parameters

string $value
string $language

Return Value

string

static string before(string $subject, string $search)

Get the portion of a string before the first occurrence of a given value.

Parameters

string $subject
string $search

Return Value

string

static string beforeLast(string $subject, string $search)

Get the portion of a string before the last occurrence of a given value.

Parameters

string $subject
string $search

Return Value

string

static string between(string $subject, string $from, string $to)

Get the portion of a string between two given values.

Parameters

string $subject
string $from
string $to

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|string[] $needles)

Determine if a given string contains a given substring.

Parameters

string $haystack
string|string[] $needles

Return Value

bool

static bool containsAll(string $haystack, array $needles)

Determine if a given string contains all array values.

Parameters

string $haystack
array $needles

Return Value

bool

static bool endsWith(string $haystack, string|string[] $needles)

Determine if a given string ends with a given substring.

Parameters

string $haystack
string|string[] $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|array $pattern, string $value)

Determine if a given string matches a given pattern.

Parameters

string|array $pattern
string $value

Return Value

bool

static bool isAscii(string $value)

Determine if a given string is 7 bit ASCII.

Parameters

string $value

Return Value

bool

static bool isUuid(string $value)

Determine if a given string is a valid UUID.

Parameters

string $value

Return Value

bool

static string kebab(string $value)

Convert a string to kebab case.

Parameters

string $value

Return Value

string

static int length(string $value, string|null $encoding = null)

Return the length of the given string.

Parameters

string $value
string|null $encoding

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 string padBoth(string $value, int $length, string $pad = ' ')

Pad both sides of a string with another.

Parameters

string $value
int $length
string $pad

Return Value

string

static string padLeft(string $value, int $length, string $pad = ' ')

Pad the left side of a string with another.

Parameters

string $value
int $length
string $pad

Return Value

string

static string padRight(string $value, int $length, string $pad = ' ')

Pad the right side of a string with another.

Parameters

string $value
int $length
string $pad

Return Value

string

static array<int,string|null> parseCallback(string $callback, string|null $default = null)

Parse a Class[@]method style callback into class and method.

Parameters

string $callback
string|null $default

Return Value

array<int,string|null>

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

Pluralize the last word of an English, studly caps case string.

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

static string replaceArray(string $search, array $replace, string $subject)

Replace a given value in the string sequentially with an array.

Parameters

string $search
array $replace
string $subject

Return Value

string

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

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

static string start(string $value, string $prefix)

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

Parameters

string $value
string $prefix

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 = '-', string|null $language = 'en')

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

Parameters

string $title
string $separator
string|null $language

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|string[] $needles)

Determine if a given string starts with a given substring.

Parameters

string $haystack
string|string[] $needles

Return Value

bool

static string studly(string $value)

Convert a value to studly caps case.

Parameters

string $value

Return Value

string

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

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

Parameters

string $string
int $start
int|null $length

Return Value

string

static int substrCount(string $haystack, string $needle, int $offset = 0, int|null $length = null)

Returns the number of substring occurrences.

Parameters

string $haystack
string $needle
int $offset
int|null $length

Return Value

int

static string ucfirst(string $string)

Make a string's first character uppercase.

Parameters

string $string

Return Value

string

static UuidInterface uuid()

Generate a UUID (version 4).

Return Value

UuidInterface

static UuidInterface orderedUuid()

Generate a time-ordered UUID (version 4).

Return Value

UuidInterface

static void createUuidsUsing(callable $factory = null)

Set the callable that will be used to generate UUIDs.

Parameters

callable $factory

Return Value

void

static void createUuidsNormally()

Indicate that UUIDs should be created normally and not using a custom factory.

Return Value

void

© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/8.x/Illuminate/Support/Str.html