Str
class Str
String utility class.
Methods
Get the portion of a string after the first occurrence of a given value.
Convert a string to its ASCII representation.
Base64 encode a string.
Base64 decode a string.
Get the portion of a string before the first occurrence of a given value.
Get the substring between two given substrings.
Convert a string to camelCase.
Split a string into chunks.
Compare two strings.
Determine if a string contains a given substring.
Calculate CRC32 hash of a string.
Determine if a string ends with a given substring.
Create excerpts around specific words within a string.
Ensure a string ends with a given value.
Convert a string to headline case.
Check if the given string is pure ASCII.
Determine if a string is empty.
Determine if a string is a valid JSON.
Check if a string is a valid UUID.
Convert a string to kebab-case.
Find the position of the last occurrence of a substring.
Converts the first character of a string to lowercase.
Get the length of a string using multibyte support.
Calculate Levenshtein distance between two strings.
Limit the number of characters in a string.
Convert a string to lowercase.
Mask portions of a string with a given character.
Return the MD5 hash of a string.
Format a number with grouped thousands.
Pad the left side of a string with a given character.
Pad the right side of a string with a given character.
Convert a string to PascalCase (StudlyCase).
Pluralize a word.
Find the position of the first occurrence of a substring.
Generate a random string of a specified length.
Repeat a string.
Replace all occurrences of the search string with the replacement string.
Replace placeholders sequentially with values from an array.
Replace the first occurrence of a substring.
Replace the last occurrence of a substring.
Replace multiple occurrences of different values in a string.
Reverse a given string.
Return the SHA1 hash of a string.
Shuffle characters in a string.
Calculate similarity between two strings.
Convert a string to snake_case.
Convert a string to a URL-friendly slug.
Remove excessive whitespace from a string.
Determine if a string starts with a given substring.
Strip all whitespace from a string.
Convert a string to StudlyCase (PascalCase).
Get a part of a string.
Count occurrences of a substring.
Swap keys with values in an array and return as a string.
Convert a string to title case.
Convert a string into an array.
Capitalize the first character of a string.
Capitalize the first letter of each word.
Convert a string to UPPERCASE.
Generate a UUID (Universally Unique Identifier).
Count the number of words in a string.
Limit a string to a certain number of words.
Wrap a string with a given value.
Details
at line 21
static string
after(string $subject, string $search)
Get the portion of a string after the first occurrence of a given value.
at line 34
static string
ascii(string $value)
Convert a string to its ASCII representation.
at line 44
static string
base64Encode(string $value)
Base64 encode a string.
at line 54
static string
base64Decode(string $value)
Base64 decode a string.
at line 65
static string
before(string $subject, string $search)
Get the portion of a string before the first occurrence of a given value.
at line 79
static string
between(string $value, string $start, string $end)
Get the substring between two given substrings.
at line 92
static string
camel(string $value)
Convert a string to camelCase.
at line 103
static array
chunk(string $value, int $length = 1)
Split a string into chunks.
at line 114
static int
compare(string $string1, string $string2)
Compare two strings.
at line 125
static bool
contains(string $haystack, string $needle)
Determine if a string contains a given substring.
at line 135
static int
crc32(string $value)
Calculate CRC32 hash of a string.
at line 146
static bool
endsWith(string $haystack, string $needle)
Determine if a string ends with a given substring.
at line 158
static string
excerpt(string $text, string $phrase, int $radius = 100)
Create excerpts around specific words within a string.
at line 175
static string
finish(string $value, string $cap)
Ensure a string ends with a given value.
at line 185
static string
headline(string $value)
Convert a string to headline case.
at line 195
static bool
isAscii(string $value)
Check if the given string is pure ASCII.
at line 205
static bool
isEmpty(string $value)
Determine if a string is empty.
at line 215
static bool
isJson(string $value)
Determine if a string is a valid JSON.
at line 226
static bool
isUuid(string $value)
Check if a string is a valid UUID.
at line 236
static string
kebab(string $value)
Convert a string to kebab-case.
at line 248
static int|false
lastPosition(string $haystack, string $needle)
Find the position of the last occurrence of a substring.
at line 259
static string
lcfirst(string $value)
Converts the first character of a string to lowercase.
at line 269
static int
length(string $value)
Get the length of a string using multibyte support.
at line 280
static int
levenshtein(string $string1, string $string2)
Calculate Levenshtein distance between two strings.
at line 292
static string
limit(string $value, int $limit = 100, string $end = '...')
Limit the number of characters in a string.
at line 302
static string
lower(string $value)
Convert a string to lowercase.
at line 315
static string
mask(string $string, string $character = '*', int $start = 0, int|null $length = null)
Mask portions of a string with a given character.
at line 328
static string
md5(string $value)
Return the MD5 hash of a string.
at line 341
static string
numberFormat(float $number, int $decimals = 0, string $decimalSeparator = '.', string $thousandSeparator = ',')
Format a number with grouped thousands.
at line 353
static string
padLeft(string $value, int $length, string $pad = ' ')
Pad the left side of a string with a given character.
at line 365
static string
padRight(string $value, int $length, string $pad = ' ')
Pad the right side of a string with a given character.
at line 375
static string
pascal(string $value)
Convert a string to PascalCase (StudlyCase).
at line 386
static string
plural(string $word, int $count = 2)
Pluralize a word.
at line 399
static int|false
position(string $haystack, string $needle)
Find the position of the first occurrence of a substring.
at line 409
static string
random(int $length = 16)
Generate a random string of a specified length.
at line 420
static string
repeat(string $value, int $times)
Repeat a string.
at line 433
static string
replace(string|array $search, string|array $replace, string $subject)
Replace all occurrences of the search string with the replacement string.
at line 444
static string
replaceArray(string $search, array $replace, string $subject)
Replace placeholders sequentially with values from an array.
at line 460
static string
replaceFirst(string $search, string $replace, string $subject)
Replace the first occurrence of a substring.
at line 473
static string
replaceLast(string $search, string $replace, string $subject)
Replace the last occurrence of a substring.
at line 485
static string
replaceMultiple(array $replacements, string $subject)
Replace multiple occurrences of different values in a string.
at line 495
static string
reverse(string $value)
Reverse a given string.
at line 505
static string
sha1(string $value)
Return the SHA1 hash of a string.
at line 515
static string
shuffle(string $value)
Shuffle characters in a string.
at line 526
static int
similarity(string $string1, string $string2)
Calculate similarity between two strings.
at line 538
static string
snake(string $value, string $delimiter = '_')
Convert a string to snake_case.
at line 551
static string
slug(string $title, string $separator = '-')
Convert a string to a URL-friendly slug.
at line 562
static string
squish(string $value)
Remove excessive whitespace from a string.
at line 573
static bool
startsWith(string $haystack, string $needle)
Determine if a string starts with a given substring.
at line 583
static string
stripWhitespace(string $value)
Strip all whitespace from a string.
at line 593
static string
studly(string $value)
Convert a string to StudlyCase (PascalCase).
at line 605
static string
substr(string $value, int $start, int|null $length = null)
Get a part of a string.
at line 616
static int
substrCount(string $haystack, string $needle)
Count occurrences of a substring.
at line 626
static string
swapKeyValue(array $array)
Swap keys with values in an array and return as a string.
at line 636
static string
title(string $value)
Convert a string to title case.
at line 646
static array
toArray(string $value)
Convert a string into an array.
at line 656
static string
ucfirst(string $value)
Capitalize the first character of a string.
at line 666
static string
ucwords(string $value)
Capitalize the first letter of each word.
at line 676
static string
upper(string $value)
Convert a string to UPPERCASE.
at line 684
static string
uuid()
Generate a UUID (Universally Unique Identifier).
at line 694
static int
wordCount(string $value)
Count the number of words in a string.
at line 706
static string
words(string $value, int $words = 10, string $end = '...')
Limit a string to a certain number of words.
at line 718
static string
wrap(string $value, string $wrapWith)
Wrap a string with a given value.