Str
class Str (View source)
Traits
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
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Get a new stringable object from the given string.
Return the remainder of a string after the first occurrence of a given value.
Return the remainder of a string after the last occurrence of a given value.
Transliterate a UTF-8 value to ASCII.
Transliterate a string to its closest ASCII representation.
Get the portion of a string before the first occurrence of a given value.
Get the portion of a string before the last occurrence of a given value.
Get the portion of a string between two given values.
Convert a value to camel case.
Determine if a given string contains a given substring.
Determine if a given string contains all array values.
Determine if a given string ends with a given substring.
Cap a string with a single instance of a given value.
Determine if a given string matches a given pattern.
Determine if a given string is 7 bit ASCII.
Determine if a given string is a valid UUID.
Convert a string to kebab case.
Return the length of the given string.
Limit the number of characters in a string.
Convert the given string to lower-case.
Limit the number of words in a string.
Converts GitHub flavored Markdown into HTML.
Masks a portion of a string with a repeated character.
Get the string matching the given pattern.
Get the string matching the given pattern.
Pad both sides of a string with another.
Pad the left side of a string with another.
Pad the right side of a string with another.
Parse a Class[@]method style callback into class and method.
Pluralize the last word of an English, studly caps case string.
Generate a more truly "random" alpha-numeric string.
Repeat the given string.
Replace a given value in the string sequentially with an array.
Replace the given value in the given string.
Replace the first occurrence of a given value in the string.
Replace the last occurrence of a given value in the string.
Remove any occurrence of the given string in the subject.
Reverse the given string.
Begin a string with a single instance of a given value.
Convert the given string to upper-case.
Convert the given string to title case.
Convert the given string to title case for each word.
Get the singular form of an English word.
Generate a URL friendly "slug" from a given string.
Convert a string to snake case.
Determine if a given string starts with a given substring.
Convert a value to studly caps case.
Returns the portion of the string specified by the start and length parameters.
Returns the number of substring occurrences.
Replace text within a portion of a string.
Swap multiple keywords in a string with other keywords.
Make a string's first character uppercase.
Split a string into pieces by uppercase characters.
Get the number of words a string contains.
Generate a UUID (version 4).
Generate a time-ordered UUID (version 4).
Set the callable that will be used to generate UUIDs.
Indicate that UUIDs should be created normally and not using a custom factory.
Remove all strings from the casing caches.
Details
static void
macro(string $name, object|callable $macro)
Register a custom macro.
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
static bool
hasMacro(string $name)
Checks if macro is registered.
static void
flushMacros()
Flush the existing macros.
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 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
transliterate(string $string, string|null $unknown = '?', bool|null $strict = false)
Transliterate a string to its closest ASCII representation.
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
markdown(string $string, array $options = [])
Converts GitHub flavored Markdown into HTML.
static string
mask(string $string, string $character, int $index, int|null $length = null, string $encoding = 'UTF-8')
Masks a portion of a string with a repeated character.
static string
match(string $pattern, string $subject)
Get the string matching the given pattern.
static Collection
matchAll(string $pattern, string $subject)
Get the string matching the given pattern.
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|array|Countable $count = 2)
Get the plural form of an English word.
static string
pluralStudly(string $value, int|array|Countable $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
repeat(string $string, int $times)
Repeat the given string.
static string
replaceArray(string $search, array $replace, string $subject)
Replace a given value in the string sequentially with an array.
static string
replace(string|string[] $search, string|string[] $replace, string|string[] $subject)
Replace the given value in the given string.
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
remove(string|string[] $search, string $subject, bool $caseSensitive = true)
Remove any occurrence of the given string in the subject.
static string
reverse(string $value)
Reverse the given 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
headline(string $value)
Convert the given string to title case for each word.
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 the 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|array
substrReplace(string|array $string, string|array $replace, array|int $offset = 0, array|int|null $length = null)
Replace text within a portion of a string.
static string
swap(array $map, string $subject)
Swap multiple keywords in a string with other keywords.
static string
ucfirst(string $string)
Make a string's first character uppercase.
static array
ucsplit(string $string)
Split a string into pieces by uppercase characters.
static int
wordCount(string $string)
Get the number of words a string contains.
static UuidInterface
uuid()
Generate a UUID (version 4).
static UuidInterface
orderedUuid()
Generate a time-ordered UUID (version 4).
static void
createUuidsUsing(callable|null $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.
static void
flushCache()
Remove all strings from the casing caches.
Laravel Cloud is the best place to deploy Laravel, Nuxt, Express, Hono, Node.js, Bun, Go, Flask, Python, and more, with dedicated infrastructure available on AWS through Laravel Private Cloud.