Documentation

Str extends Str
in package

String helper

Tags
author

Alexey Bobkov, Samuel Georges

Table of Contents

$camelCache  : array<string|int, mixed>
The cache of camel-cased words.
$macros  : array<string|int, mixed>
The registered string macros.
$snakeCache  : array<string|int, mixed>
The cache of snake-cased words.
$studlyCache  : array<string|int, mixed>
The cache of studly-cased words.
__call()  : mixed
Dynamically handle calls to the class.
__callStatic()  : mixed
Dynamically handle calls to the class.
after()  : string
Return the remainder of a string after a given value.
ascii()  : string
Transliterate a UTF-8 value to ASCII.
before()  : string
Get the portion of a string before a given value.
camel()  : string
Convert a value to camel case.
contains()  : bool
Determine if a given string contains a given substring.
endsWith()  : bool
Determine if a given string ends with a given substring.
finish()  : string
Cap a string with a single instance of a given value.
getClassId()  : mixed
Generates a class ID from either an object or a string of the class name.
getClassNamespace()  : mixed
Returns a class namespace
getPrecedingSymbols()  : int
If $string begins with any number of consecutive symbols, returns the number, otherwise returns 0
hasMacro()  : bool
Checks if macro is registered.
is()  : bool
Determine if a given string matches a given pattern.
kebab()  : string
Convert a string to kebab case.
length()  : int
Return the length of the given string.
limit()  : string
Limit the number of characters in a string.
lower()  : string
Convert the given string to lower-case.
macro()  : void
Register a custom macro.
mixin()  : void
Mix another object into the class.
normalizeClassName()  : mixed
Removes the starting slash from a class namespace \
normalizeEol()  : mixed
Converts line breaks to a standard \r\n pattern.
ordinal()  : string
Converts number to its ordinal English form.
parseCallback()  : array<string|int, mixed>
Parse a Class@method style callback into class and method.
plural()  : string
Get the plural form of an English word.
random()  : string
Generate a more truly "random" alpha-numeric string.
replaceArray()  : string
Replace a given value in the string sequentially with an array.
replaceFirst()  : string
Replace the first occurrence of a given value in the string.
replaceLast()  : string
Replace the last occurrence of a given value in the string.
singular()  : string
Get the singular form of an English word.
slug()  : string
Generate a URL friendly "slug" from a given string.
snake()  : string
Convert a string to snake case.
start()  : string
Begin a string with a single instance of a given value.
startsWith()  : bool
Determine if a given string starts with a given substring.
studly()  : string
Convert a value to studly caps case.
substr()  : string
Returns the portion of string specified by the start and length parameters.
title()  : string
Convert the given string to title case.
ucfirst()  : string
Make a string's first character uppercase.
upper()  : string
Convert the given string to upper-case.
words()  : string
Limit the number of words in a string.
charsArray()  : array<string|int, mixed>
Returns the replacements for the ascii method.
languageSpecificCharsArray()  : array<string|int, mixed>|null
Returns the language specific replacements for the ascii method.

Properties

$camelCache

The cache of camel-cased words.

protected static array<string|int, mixed> $camelCache = []

$macros

The registered string macros.

protected static array<string|int, mixed> $macros = []

$snakeCache

The cache of snake-cased words.

protected static array<string|int, mixed> $snakeCache = []

$studlyCache

The cache of studly-cased words.

protected static array<string|int, mixed> $studlyCache = []

Methods

__call()

Dynamically handle calls to the class.

public __call(string $method, array<string|int, mixed> $parameters) : mixed
Parameters
$method : string
$parameters : array<string|int, mixed>
Tags
throws
BadMethodCallException
Return values
mixed

__callStatic()

Dynamically handle calls to the class.

public static __callStatic(string $method, array<string|int, mixed> $parameters) : mixed
Parameters
$method : string
$parameters : array<string|int, mixed>
Tags
throws
BadMethodCallException
Return values
mixed

after()

Return the remainder of a string after a given value.

public static after(string $subject, string $search) : string
Parameters
$subject : string
$search : string
Return values
string

ascii()

Transliterate a UTF-8 value to ASCII.

public static ascii(string $value[, string $language = 'en' ]) : string
Parameters
$value : string
$language : string = 'en'
Return values
string

before()

Get the portion of a string before a given value.

public static before(string $subject, string $search) : string
Parameters
$subject : string
$search : string
Return values
string

camel()

Convert a value to camel case.

public static camel(string $value) : string
Parameters
$value : string
Return values
string

contains()

Determine if a given string contains a given substring.

public static contains(string $haystack, string|array<string|int, mixed> $needles) : bool
Parameters
$haystack : string
$needles : string|array<string|int, mixed>
Return values
bool

endsWith()

Determine if a given string ends with a given substring.

public static endsWith(string $haystack, string|array<string|int, mixed> $needles) : bool
Parameters
$haystack : string
$needles : string|array<string|int, mixed>
Return values
bool

finish()

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

public static finish(string $value, string $cap) : string
Parameters
$value : string
$cap : string
Return values
string

getClassId()

Generates a class ID from either an object or a string of the class name.

public static getClassId(mixed $name) : mixed
Parameters
$name : mixed
Return values
mixed

getClassNamespace()

Returns a class namespace

public static getClassNamespace(mixed $name) : mixed
Parameters
$name : mixed
Return values
mixed

getPrecedingSymbols()

If $string begins with any number of consecutive symbols, returns the number, otherwise returns 0

public static getPrecedingSymbols(string $string, string $symbol) : int
Parameters
$string : string
$symbol : string
Return values
int

hasMacro()

Checks if macro is registered.

public static hasMacro(string $name) : bool
Parameters
$name : string
Return values
bool

is()

Determine if a given string matches a given pattern.

public static is(string|array<string|int, mixed> $pattern, string $value) : bool
Parameters
$pattern : string|array<string|int, mixed>
$value : string
Return values
bool

kebab()

Convert a string to kebab case.

public static kebab(string $value) : string
Parameters
$value : string
Return values
string

length()

Return the length of the given string.

public static length(string $value[, string $encoding = null ]) : int
Parameters
$value : string
$encoding : string = null
Return values
int

limit()

Limit the number of characters in a string.

public static limit(string $value[, int $limit = 100 ][, string $end = '...' ]) : string
Parameters
$value : string
$limit : int = 100
$end : string = '...'
Return values
string

lower()

Convert the given string to lower-case.

public static lower(string $value) : string
Parameters
$value : string
Return values
string

macro()

Register a custom macro.

public static macro(string $name, object|callable $macro) : void
Parameters
$name : string
$macro : object|callable
Return values
void

mixin()

Mix another object into the class.

public static mixin(object $mixin) : void
Parameters
$mixin : object
Return values
void

normalizeClassName()

Removes the starting slash from a class namespace \

public static normalizeClassName(mixed $name) : mixed
Parameters
$name : mixed
Return values
mixed

normalizeEol()

Converts line breaks to a standard \r\n pattern.

public static normalizeEol(mixed $string) : mixed
Parameters
$string : mixed
Return values
mixed

ordinal()

Converts number to its ordinal English form.

public static ordinal(int $number) : string

This method converts 13 to 13th, 2 to 2nd ...

Parameters
$number : int

Number to get its ordinal value

Return values
string

Ordinal representation of given string.

parseCallback()

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

public static parseCallback(string $callback[, string|null $default = null ]) : array<string|int, mixed>
Parameters
$callback : string
$default : string|null = null
Return values
array<string|int, mixed>

plural()

Get the plural form of an English word.

public static plural(string $value[, int $count = 2 ]) : string
Parameters
$value : string
$count : int = 2
Return values
string

random()

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

public static random([int $length = 16 ]) : string
Parameters
$length : int = 16
Return values
string

replaceArray()

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

public static replaceArray(string $search, array<string|int, mixed> $replace, string $subject) : string
Parameters
$search : string
$replace : array<string|int, mixed>
$subject : string
Return values
string

replaceFirst()

Replace the first occurrence of a given value in the string.

public static replaceFirst(string $search, string $replace, string $subject) : string
Parameters
$search : string
$replace : string
$subject : string
Return values
string

replaceLast()

Replace the last occurrence of a given value in the string.

public static replaceLast(string $search, string $replace, string $subject) : string
Parameters
$search : string
$replace : string
$subject : string
Return values
string

singular()

Get the singular form of an English word.

public static singular(string $value) : string
Parameters
$value : string
Return values
string

slug()

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

public static slug(string $title[, string $separator = '-' ][, string $language = 'en' ]) : string
Parameters
$title : string
$separator : string = '-'
$language : string = 'en'
Return values
string

snake()

Convert a string to snake case.

public static snake(string $value[, string $delimiter = '_' ]) : string
Parameters
$value : string
$delimiter : string = '_'
Return values
string

start()

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

public static start(string $value, string $prefix) : string
Parameters
$value : string
$prefix : string
Return values
string

startsWith()

Determine if a given string starts with a given substring.

public static startsWith(string $haystack, string|array<string|int, mixed> $needles) : bool
Parameters
$haystack : string
$needles : string|array<string|int, mixed>
Return values
bool

studly()

Convert a value to studly caps case.

public static studly(string $value) : string
Parameters
$value : string
Return values
string

substr()

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

public static substr(string $string, int $start[, int|null $length = null ]) : string
Parameters
$string : string
$start : int
$length : int|null = null
Return values
string

title()

Convert the given string to title case.

public static title(string $value) : string
Parameters
$value : string
Return values
string

ucfirst()

Make a string's first character uppercase.

public static ucfirst(string $string) : string
Parameters
$string : string
Return values
string

upper()

Convert the given string to upper-case.

public static upper(string $value) : string
Parameters
$value : string
Return values
string

words()

Limit the number of words in a string.

public static words(string $value[, int $words = 100 ][, string $end = '...' ]) : string
Parameters
$value : string
$words : int = 100
$end : string = '...'
Return values
string

languageSpecificCharsArray()

Returns the language specific replacements for the ascii method.

protected static languageSpecificCharsArray(string $language) : array<string|int, mixed>|null

Note: Adapted from Stringy\Stringy.

Parameters
$language : string
Tags
see
https://github.com/danielstjules/Stringy/blob/3.1.0/LICENSE.txt
Return values
array<string|int, mixed>|null

Search results