PHP Class Spatie\String\Str

See also: Underscore\Methods\StringsMethods
Inheritance: implements ArrayAcces\ArrayAccess
Show file Open project: spatie/string

Protected Properties

Property Type Description
$string string

Public Methods

Method Description
__call ( $method, $args ) : mixed | Str Unknown methods calls will be handled by various integrations.
__construct ( string $string = '' )
__toString ( ) : string
between ( $start, $end ) : Str Get the string between the given start and end.
concat ( $string ) : Str Concatenate a string.
contains ( array | string $needle, boolean $caseSensitive = false, boolean $absolute = false ) : boolean Alias for find.
firstSegment ( string $delimiter ) : Str Get the first segment from a string based on a delimiter.
lastSegment ( string $delimiter ) : Str Get the last segment from a string based on a delimiter.
offsetExists ( mixed $offset ) : boolean Whether a offset exists.
offsetGet ( mixed $offset ) : mixed Offset to retrieve.
offsetSet ( mixed $offset, mixed $value ) Offset to set.
offsetUnset ( mixed $offset ) Offset to unset.
pop ( string $delimiter ) : Str Pop (remove) the last segment of a string based on a delimiter.
possessive ( ) : Str Get the possessive version of a string.
prefix ( $string ) : Str Prefix a string.
replaceFirst ( $search, $replace ) : Str Replace the first occurrence of a string.
replaceLast ( $search, $replace ) : Str Replace the last occurrence of a string.
segment ( string $delimiter, integer $index ) : Str Get a segment from a string based on a delimiter.
suffix ( $string ) : Str Suffix a string.
tease ( integer $length = 200, string $moreTextIndicator = '...' ) : Str Shortens a string in a pretty way. It will clean it by trimming it, remove all double spaces and html. If the string is then still longer than the specified $length it will be shortened. The end of the string is always a full word concatinated with the specified moreTextIndicator.
toLower ( ) : Str Convert the string to lowercase.
toUpper ( ) : Str Convert the string to uppercase.
trim ( string $characterMask = " " ) : Str Strip whitespace (or other characters) from the beginning and end of a string.

Private Methods

Method Description
sanitizeForTease ( $string ) : string Sanitize the string for teasing.

Method Details

__call() public method

Unknown methods calls will be handled by various integrations.
public __call ( $method, $args ) : mixed | Str
$method
$args
return mixed | Str

__construct() public method

public __construct ( string $string = '' )
$string string

__toString() public method

public __toString ( ) : string
return string

between() public method

Get the string between the given start and end.
public between ( $start, $end ) : Str
$start
$end
return Str

concat() public method

Concatenate a string.
public concat ( $string ) : Str
$string
return Str

contains() public method

Alias for find.
public contains ( array | string $needle, boolean $caseSensitive = false, boolean $absolute = false ) : boolean
$needle array | string
$caseSensitive boolean
$absolute boolean
return boolean

firstSegment() public method

Get the first segment from a string based on a delimiter.
public firstSegment ( string $delimiter ) : Str
$delimiter string
return Str

lastSegment() public method

Get the last segment from a string based on a delimiter.
public lastSegment ( string $delimiter ) : Str
$delimiter string
return Str

offsetExists() public method

Whether a offset exists.
public offsetExists ( mixed $offset ) : boolean
$offset mixed An offset to check for.
return boolean true on success or false on failure. The return value will be casted to boolean if non-boolean was returned.

offsetGet() public method

Offset to retrieve.
public offsetGet ( mixed $offset ) : mixed
$offset mixed The offset to retrieve.
return mixed Can return all value types.

offsetSet() public method

Offset to set.
public offsetSet ( mixed $offset, mixed $value )
$offset mixed The offset to assign the value to.
$value mixed The value to set.

offsetUnset() public method

Offset to unset.
public offsetUnset ( mixed $offset )
$offset mixed The offset to unset.

pop() public method

Pop (remove) the last segment of a string based on a delimiter.
public pop ( string $delimiter ) : Str
$delimiter string
return Str

possessive() public method

Get the possessive version of a string.
public possessive ( ) : Str
return Str

prefix() public method

Prefix a string.
public prefix ( $string ) : Str
$string
return Str

replaceFirst() public method

Replace the first occurrence of a string.
public replaceFirst ( $search, $replace ) : Str
$search
$replace
return Str

replaceLast() public method

Replace the last occurrence of a string.
public replaceLast ( $search, $replace ) : Str
$search
$replace
return Str

segment() public method

Returns an empty string when the offset doesn't exist. Use a negative index to start counting from the last element.
public segment ( string $delimiter, integer $index ) : Str
$delimiter string
$index integer
return Str

suffix() public method

Suffix a string.
public suffix ( $string ) : Str
$string
return Str

tease() public method

Shortens a string in a pretty way. It will clean it by trimming it, remove all double spaces and html. If the string is then still longer than the specified $length it will be shortened. The end of the string is always a full word concatinated with the specified moreTextIndicator.
public tease ( integer $length = 200, string $moreTextIndicator = '...' ) : Str
$length integer
$moreTextIndicator string
return Str

toLower() public method

Convert the string to lowercase.
public toLower ( ) : Str
return Str

toUpper() public method

Convert the string to uppercase.
public toUpper ( ) : Str
return Str

trim() public method

Strip whitespace (or other characters) from the beginning and end of a string.
public trim ( string $characterMask = " " ) : Str
$characterMask string
return Str

Property Details

$string protected property

protected string $string
return string