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).
Pluralizes a given word based on the count.
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 22
static string
after(string $subject, string $search)
Get the portion of a string after the first occurrence of a given value.
at line 36
static string
ascii(string $value)
Convert a string to its ASCII representation.
at line 47
static string
base64Encode(string $value)
Base64 encode a string.
at line 58
static string
base64Decode(string $value)
Base64 decode a string.
at line 70
static string
before(string $subject, string $search)
Get the portion of a string before the first occurrence of a given value.
at line 85
static string
between(string $value, string $start, string $end)
Get the substring between two given substrings.
at line 99
static string
camel(string $value)
Convert a string to camelCase.
at line 111
static array
chunk(string $value, int $length = 1)
Split a string into chunks.
at line 123
static int
compare(string $string1, string $string2)
Compare two strings.
at line 135
static bool
contains(string $haystack, string $needle)
Determine if a string contains a given substring.
at line 146
static int
crc32(string $value)
Calculate CRC32 hash of a string.
at line 159
static bool
endsWith(string $haystack, string $needle)
Determine if a string ends with a given substring.
at line 172
static string
excerpt(string $text, string $phrase, int $radius = 100)
Create excerpts around specific words within a string.
at line 190
static string
finish(string $value, string $cap)
Ensure a string ends with a given value.
at line 201
static string
headline(string $value)
Convert a string to headline case.
at line 212
static bool
isAscii(string $value)
Check if the given string is pure ASCII.
at line 223
static bool
isEmpty(string $value)
Determine if a string is empty.
at line 234
static bool
isJson(string $value)
Determine if a string is a valid JSON.
at line 246
static bool
isUuid(string $value)
Check if a string is a valid UUID.
at line 257
static string
kebab(string $value)
Convert a string to kebab-case.
at line 272
static int|false
lastPosition(string $haystack, string $needle)
Find the position of the last occurrence of a substring.
at line 283
static string
lcfirst(string $value)
Converts the first character of a string to lowercase.
at line 295
static int
length(string $value)
Get the length of a string using multibyte support.
at line 309
static int
levenshtein(string $string1, string $string2)
Calculate Levenshtein distance between two strings.
at line 322
static string
limit(string $value, int $limit = 100, string $end = '...')
Limit the number of characters in a string.
at line 333
static string
lower(string $value)
Convert a string to lowercase.
at line 347
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 361
static string
md5(string $value)
Return the MD5 hash of a string.
at line 375
static string
numberFormat(float $number, int $decimals = 0, string $decimalSeparator = '.', string $thousandSeparator = ',')
Format a number with grouped thousands.
at line 388
static string
padLeft(string $value, int $length, string $pad = ' ')
Pad the left side of a string with a given character.
at line 401
static string
padRight(string $value, int $length, string $pad = ' ')
Pad the right side of a string with a given character.
at line 412
static string
pascal(string $value)
Convert a string to PascalCase (StudlyCase).
at line 424
static string
plural(string $word, int $count = 2)
Pluralizes a given word based on the count.
at line 440
static int|false
position(string $haystack, string $needle)
Find the position of the first occurrence of a substring.
at line 451
static string
random(int $length = 16)
Generate a random string of a specified length.
at line 463
static string
repeat(string $value, int $times)
Repeat a string.
at line 476
static string
replace(string|array $search, string|array $replace, string $subject)
Replace all occurrences of the search string with the replacement string.
at line 488
static string
replaceArray(string $search, array $replace, string $subject)
Replace placeholders sequentially with values from an array.
at line 505
static string
replaceFirst(string $search, string $replace, string $subject)
Replace the first occurrence of a substring.
at line 519
static string
replaceLast(string $search, string $replace, string $subject)
Replace the last occurrence of a substring.
at line 532
static string
replaceMultiple(array $replacements, string $subject)
Replace multiple occurrences of different values in a string.
at line 543
static string
reverse(string $value)
Reverse a given string.
at line 554
static string
sha1(string $value)
Return the SHA1 hash of a string.
at line 565
static string
shuffle(string $value)
Shuffle characters in a string.
at line 577
static int
similarity(string $string1, string $string2)
Calculate similarity between two strings.
at line 590
static string
snake(string $value, string $delimiter = '_')
Convert a string to snake_case.
at line 604
static string
slug(string $title, string $separator = '-')
Convert a string to a URL-friendly slug.
at line 616
static string
squish(string $value)
Remove excessive whitespace from a string.
at line 628
static bool
startsWith(string $haystack, string $needle)
Determine if a string starts with a given substring.
at line 639
static string
stripWhitespace(string $value)
Strip all whitespace from a string.
at line 650
static string
studly(string $value)
Convert a string to StudlyCase (PascalCase).
at line 663
static string
substr(string $value, int $start, int|null $length = null)
Get a part of a string.
at line 675
static int
substrCount(string $haystack, string $needle)
Count occurrences of a substring.
at line 686
static string
swapKeyValue(array $array)
Swap keys with values in an array and return as a string.
at line 697
static string
title(string $value)
Convert a string to title case.
at line 708
static array
toArray(string $value)
Convert a string into an array.
at line 719
static string
ucfirst(string $value)
Capitalize the first character of a string.
at line 730
static string
ucwords(string $value)
Capitalize the first letter of each word.
at line 741
static string
upper(string $value)
Convert a string to UPPERCASE.
at line 751
static string
uuid()
Generate a UUID (Universally Unique Identifier).
at line 762
static int
wordCount(string $value)
Count the number of words in a string.
at line 775
static string
words(string $value, int $words = 10, string $end = '...')
Limit a string to a certain number of words.
at line 788
static string
wrap(string $value, string $wrapWith)
Wrap a string with a given value.