PHP Класс Stringy\Stringy

Наследование: implements Countable, implements IteratorAggregate, implements ArrayAccess
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$encoding string The string's encoding, which should be one of the mbstring module's supported encodings.
$str string An instance's string.

Открытые методы

Метод Описание
__construct ( mixed $str = '', string $encoding = null ) Initializes a Stringy object and assigns both str and encoding properties the supplied values. $str is cast to a string prior to assignment, and if $encoding is not specified, it defaults to mb_internal_encoding(). Throws an InvalidArgumentException if the first argument is an array or object without a __toString method.
__toString ( ) : string Returns the value in $str.
append ( string $string ) : Stringy Returns a new string with $string appended.
at ( integer $index ) : Stringy Returns the character at $index, with indexes starting at 0.
between ( string $start, string $end, integer $offset ) : Stringy Returns the substring between $start and $end, if found, or an empty string. An optional offset may be supplied from which to begin the search for the start string.
camelize ( ) : Stringy Returns a camelCase version of the string. Trims surrounding spaces, capitalizes letters following digits, spaces, dashes and underscores, and removes spaces, dashes, as well as underscores.
chars ( ) : array Returns an array consisting of the characters in the string.
collapseWhitespace ( ) : Stringy Trims the string and replaces consecutive whitespace characters with a single space. This includes tabs and newline characters, as well as multibyte whitespace such as the thin space and ideographic space.
contains ( string $needle, boolean $caseSensitive = true ) : boolean Returns true if the string contains $needle, false otherwise. By default the comparison is case-sensitive, but can be made insensitive by setting $caseSensitive to false.
containsAll ( array $needles, boolean $caseSensitive = true ) : boolean Returns true if the string contains all $needles, false otherwise. By default the comparison is case-sensitive, but can be made insensitive by setting $caseSensitive to false.
containsAny ( array $needles, boolean $caseSensitive = true ) : boolean Returns true if the string contains any $needles, false otherwise. By default the comparison is case-sensitive, but can be made insensitive by setting $caseSensitive to false.
count ( ) : integer Returns the length of the string, implementing the countable interface.
countSubstr ( string $substring, boolean $caseSensitive = true ) : integer Returns the number of occurrences of $substring in the given string.
create ( mixed $str = '', string $encoding = null ) : Stringy Creates a Stringy object and assigns both str and encoding properties the supplied values. $str is cast to a string prior to assignment, and if $encoding is not specified, it defaults to mb_internal_encoding(). It then returns the initialized object. Throws an InvalidArgumentException if the first argument is an array or object without a __toString method.
dasherize ( ) : Stringy Returns a lowercase and trimmed string separated by dashes. Dashes are inserted before uppercase characters (with the exception of the first character of the string), and in place of spaces as well as underscores.
delimit ( string $delimiter ) : Stringy Returns a lowercase and trimmed string separated by the given delimiter.
endsWith ( string $substring, boolean $caseSensitive = true ) : boolean Returns true if the string ends with $substring, false otherwise. By default, the comparison is case-sensitive, but can be made insensitive by setting $caseSensitive to false.
ensureLeft ( string $substring ) : Stringy Ensures that the string begins with $substring. If it doesn't, it's prepended.
ensureRight ( string $substring ) : Stringy Ensures that the string ends with $substring. If it doesn't, it's appended.
first ( integer $n ) : Stringy Returns the first $n characters of the string.
getEncoding ( ) : string Returns the encoding used by the Stringy object.
getIterator ( ) : ArrayIterator Returns a new ArrayIterator, thus implementing the IteratorAggregate interface. The ArrayIterator's constructor is passed an array of chars in the multibyte string. This enables the use of foreach with instances of Stringy\Stringy.
hasLowerCase ( ) : boolean Returns true if the string contains a lower case char, false otherwise.
hasUpperCase ( ) : boolean Returns true if the string contains an upper case char, false otherwise.
htmlDecode ( integer | null $flags = ENT_COMPAT ) : Stringy Convert all HTML entities to their applicable characters. An alias of html_entity_decode. For a list of flags, refer to http://php.net/manual/en/function.html-entity-decode.php
htmlEncode ( integer | null $flags = ENT_COMPAT ) : Stringy Convert all applicable characters to HTML entities. An alias of htmlentities. Refer to http://php.net/manual/en/function.htmlentities.php for a list of flags.
humanize ( ) : Stringy Capitalizes the first word of the string, replaces underscores with spaces, and strips '_id'.
indexOf ( string $needle, integer $offset ) : integer | boolean Returns the index of the first occurrence of $needle in the string, and false if not found. Accepts an optional offset from which to begin the search.
indexOfLast ( string $needle, integer $offset ) : integer | boolean Returns the index of the last occurrence of $needle in the string, and false if not found. Accepts an optional offset from which to begin the search. Offsets may be negative to count from the last character in the string.
insert ( string $substring, integer $index ) : Stringy Inserts $substring into the string at the $index provided.
isAlpha ( ) : boolean Returns true if the string contains only alphabetic chars, false otherwise.
isAlphanumeric ( ) : boolean Returns true if the string contains only alphabetic and numeric chars, false otherwise.
isBase64 ( ) : boolean Returns true if the string is base64 encoded, false otherwise.
isBlank ( ) : boolean Returns true if the string contains only whitespace chars, false otherwise.
isHexadecimal ( ) : boolean Returns true if the string contains only hexadecimal chars, false otherwise.
isJson ( ) : boolean Returns true if the string is JSON, false otherwise. Unlike json_decode in PHP 5.x, this method is consistent with PHP 7 and other JSON parsers, in that an empty string is not considered valid JSON.
isLowerCase ( ) : boolean Returns true if the string contains only lower case chars, false otherwise.
isSerialized ( ) : boolean Returns true if the string is serialized, false otherwise.
isUpperCase ( ) : boolean Returns true if the string contains only lower case chars, false otherwise.
last ( integer $n ) : Stringy Returns the last $n characters of the string.
length ( ) : integer Returns the length of the string. An alias for PHP's mb_strlen() function.
lines ( ) : Stringy[] Splits on newlines and carriage returns, returning an array of Stringy objects corresponding to the lines in the string.
longestCommonPrefix ( string $otherStr ) : Stringy Returns the longest common prefix between the string and $otherStr.
longestCommonSubstring ( string $otherStr ) : Stringy Returns the longest common substring between the string and $otherStr.
longestCommonSuffix ( string $otherStr ) : Stringy Returns the longest common suffix between the string and $otherStr.
lowerCaseFirst ( ) : Stringy Converts the first character of the string to lower case.
offsetExists ( mixed $offset ) : boolean Returns whether or not a character exists at an index. Offsets may be negative to count from the last character in the string. Implements part of the ArrayAccess interface.
offsetGet ( mixed $offset ) : mixed Returns the character at the given index. Offsets may be negative to count from the last character in the string. Implements part of the ArrayAccess interface, and throws an OutOfBoundsException if the index does not exist.
offsetSet ( mixed $offset, mixed $value ) Implements part of the ArrayAccess interface, but throws an exception when called. This maintains the immutability of Stringy objects.
offsetUnset ( mixed $offset ) Implements part of the ArrayAccess interface, but throws an exception when called. This maintains the immutability of Stringy objects.
pad ( integer $length, string $padStr = ' ', string $padType = 'right' ) : Stringy Pads the string to a given length with $padStr. If length is less than or equal to the length of the string, no padding takes places. The default string used for padding is a space, and the default type (one of 'left', 'right', 'both') is 'right'. Throws an InvalidArgumentException if $padType isn't one of those 3 values.
padBoth ( integer $length, string $padStr = ' ' ) : Stringy Returns a new string of a given length such that both sides of the string are padded. Alias for pad() with a $padType of 'both'.
padLeft ( integer $length, string $padStr = ' ' ) : Stringy Returns a new string of a given length such that the beginning of the string is padded. Alias for pad() with a $padType of 'left'.
padRight ( integer $length, string $padStr = ' ' ) : Stringy Returns a new string of a given length such that the end of the string is padded. Alias for pad() with a $padType of 'right'.
prepend ( string $string ) : Stringy Returns a new string starting with $string.
regexReplace ( string $pattern, string $replacement, string $options = 'msr' ) : Stringy Replaces all occurrences of $pattern in $str by $replacement. An alias for mb_ereg_replace(). Note that the 'i' option with multibyte patterns in mb_ereg_replace() requires PHP 5.6+ for correct results. This is due to a lack of support in the bundled version of Oniguruma in PHP < 5.6, and current versions of HHVM (3.8 and below).
removeLeft ( string $substring ) : Stringy Returns a new string with the prefix $substring removed, if present.
removeRight ( string $substring ) : Stringy Returns a new string with the suffix $substring removed, if present.
repeat ( integer $multiplier ) : Stringy Returns a repeated string given a multiplier. An alias for str_repeat.
replace ( string $search, string $replacement ) : Stringy Replaces all occurrences of $search in $str by $replacement.
reverse ( ) : Stringy Returns a reversed string. A multibyte version of strrev().
safeTruncate ( integer $length, string $substring = '' ) : Stringy Truncates the string to a given length, while ensuring that it does not split words. If $substring is provided, and truncating occurs, the string is further truncated so that the substring may be appended without exceeding the desired length.
shuffle ( ) * A multibyte str_shuffle() function. It returns a string with its characters in random order.
slice ( integer $start, integer $end = null ) : Stringy Returns the substring beginning at $start, and up to, but not including the index specified by $end. If $end is omitted, the function extracts the remaining string. If $end is negative, it is computed from the end of the string.
slugify ( string $replacement = '-' ) : Stringy Converts the string into an URL slug. This includes replacing non-ASCII characters with their closest ASCII equivalents, removing remaining non-ASCII and non-alphanumeric characters, and replacing whitespace with $replacement. The replacement defaults to a single dash, and the string is also converted to lowercase.
split ( string $pattern, integer $limit = null ) : Stringy[] Splits the string with the provided regular expression, returning an array of Stringy objects. An optional integer $limit will truncate the results.
startsWith ( string $substring, boolean $caseSensitive = true ) : boolean Returns true if the string begins with $substring, false otherwise. By default, the comparison is case-sensitive, but can be made insensitive by setting $caseSensitive to false.
substr ( integer $start, integer $length = null ) : Stringy Returns the substring beginning at $start with the specified $length.
surround ( string $substring ) : Stringy Surrounds $str with the given substring.
swapCase ( ) : Stringy Returns a case swapped version of the string.
tidy ( ) : Stringy Returns a string with smart quotes, ellipsis characters, and dashes from Windows-1252 (commonly used in Word documents) replaced by their ASCII equivalents.
titleize ( array $ignore = null ) : Stringy Returns a trimmed string with the first letter of each word capitalized.
toAscii ( boolean $removeUnsupported = true ) : Stringy Returns an ASCII version of the string. A set of non-ASCII characters are replaced with their closest ASCII counterparts, and the rest are removed unless instructed otherwise.
toBoolean ( ) : boolean Returns a boolean representation of the given logical string value.
toLowerCase ( ) : Stringy Converts all characters in the string to lowercase. An alias for PHP's mb_strtolower().
toSpaces ( integer $tabLength = 4 ) : Stringy Converts each tab in the string to some number of spaces, as defined by $tabLength. By default, each tab is converted to 4 consecutive spaces.
toTabs ( integer $tabLength = 4 ) : Stringy Converts each occurrence of some consecutive number of spaces, as defined by $tabLength, to a tab. By default, each 4 consecutive spaces are converted to a tab.
toTitleCase ( ) : Stringy Converts the first character of each word in the string to uppercase.
toUpperCase ( ) : Stringy Converts all characters in the string to uppercase. An alias for PHP's mb_strtoupper().
trim ( string $chars = null ) : Stringy Returns a string with whitespace removed from the start and end of the string. Supports the removal of unicode whitespace. Accepts an optional string of characters to strip instead of the defaults.
trimLeft ( string $chars = null ) : Stringy Returns a string with whitespace removed from the start of the string.
trimRight ( string $chars = null ) : Stringy Returns a string with whitespace removed from the end of the string.
truncate ( integer $length, string $substring = '' ) : Stringy Truncates the string to a given length. If $substring is provided, and truncating occurs, the string is further truncated so that the substring may be appended without exceeding the desired length.
underscored ( ) : Stringy Returns a lowercase and trimmed string separated by underscores.
upperCamelize ( ) : Stringy Returns an UpperCamelCase version of the supplied string. It trims surrounding spaces, capitalizes letters following digits, spaces, dashes and underscores, and removes spaces, dashes, underscores.
upperCaseFirst ( ) : Stringy Converts the first character of the supplied string to upper case.

Защищенные методы

Метод Описание
charsArray ( ) : array Returns the replacements for the toAscii() method.

Приватные методы

Метод Описание
applyPadding ( integer $left, integer $right, string $padStr = ' ' ) : Stringy Adds the specified amount of left and right padding to the given string.
eregReplace ( $pattern, $replacement, $string, $option = 'msr' ) Alias for mb_ereg_replace with a fallback to preg_replace if the mbstring module is not installed.
matchesPattern ( string $pattern ) : boolean Returns true if $str matches the supplied pattern, false otherwise.
regexEncoding ( ) Alias for mb_regex_encoding which default to a noop if the mbstring module is not installed.
supportsEncoding ( )

Описание методов

__construct() публичный Метод

Initializes a Stringy object and assigns both str and encoding properties the supplied values. $str is cast to a string prior to assignment, and if $encoding is not specified, it defaults to mb_internal_encoding(). Throws an InvalidArgumentException if the first argument is an array or object without a __toString method.
public __construct ( mixed $str = '', string $encoding = null )
$str mixed Value to modify, after being cast to string
$encoding string The character encoding

__toString() публичный Метод

Returns the value in $str.
public __toString ( ) : string
Результат string The current value of the $str property

append() публичный Метод

Returns a new string with $string appended.
public append ( string $string ) : Stringy
$string string The string to append
Результат Stringy Object with appended $string

at() публичный Метод

Returns the character at $index, with indexes starting at 0.
public at ( integer $index ) : Stringy
$index integer Position of the character
Результат Stringy The character at $index

between() публичный Метод

Returns the substring between $start and $end, if found, or an empty string. An optional offset may be supplied from which to begin the search for the start string.
public between ( string $start, string $end, integer $offset ) : Stringy
$start string Delimiter marking the start of the substring
$end string Delimiter marking the end of the substring
$offset integer Index from which to begin the search
Результат Stringy Object whose $str is a substring between $start and $end

camelize() публичный Метод

Returns a camelCase version of the string. Trims surrounding spaces, capitalizes letters following digits, spaces, dashes and underscores, and removes spaces, dashes, as well as underscores.
public camelize ( ) : Stringy
Результат Stringy Object with $str in camelCase

chars() публичный Метод

Returns an array consisting of the characters in the string.
public chars ( ) : array
Результат array An array of string chars

charsArray() защищенный Метод

Returns the replacements for the toAscii() method.
protected charsArray ( ) : array
Результат array An array of replacements.

collapseWhitespace() публичный Метод

Trims the string and replaces consecutive whitespace characters with a single space. This includes tabs and newline characters, as well as multibyte whitespace such as the thin space and ideographic space.
public collapseWhitespace ( ) : Stringy
Результат Stringy Object with a trimmed $str and condensed whitespace

contains() публичный Метод

Returns true if the string contains $needle, false otherwise. By default the comparison is case-sensitive, but can be made insensitive by setting $caseSensitive to false.
public contains ( string $needle, boolean $caseSensitive = true ) : boolean
$needle string Substring to look for
$caseSensitive boolean Whether or not to enforce case-sensitivity
Результат boolean Whether or not $str contains $needle

containsAll() публичный Метод

Returns true if the string contains all $needles, false otherwise. By default the comparison is case-sensitive, but can be made insensitive by setting $caseSensitive to false.
public containsAll ( array $needles, boolean $caseSensitive = true ) : boolean
$needles array Substrings to look for
$caseSensitive boolean Whether or not to enforce case-sensitivity
Результат boolean Whether or not $str contains $needle

containsAny() публичный Метод

Returns true if the string contains any $needles, false otherwise. By default the comparison is case-sensitive, but can be made insensitive by setting $caseSensitive to false.
public containsAny ( array $needles, boolean $caseSensitive = true ) : boolean
$needles array Substrings to look for
$caseSensitive boolean Whether or not to enforce case-sensitivity
Результат boolean Whether or not $str contains $needle

count() публичный Метод

Returns the length of the string, implementing the countable interface.
public count ( ) : integer
Результат integer The number of characters in the string, given the encoding

countSubstr() публичный Метод

By default, the comparison is case-sensitive, but can be made insensitive by setting $caseSensitive to false.
public countSubstr ( string $substring, boolean $caseSensitive = true ) : integer
$substring string The substring to search for
$caseSensitive boolean Whether or not to enforce case-sensitivity
Результат integer The number of $substring occurrences

create() публичный статический Метод

Creates a Stringy object and assigns both str and encoding properties the supplied values. $str is cast to a string prior to assignment, and if $encoding is not specified, it defaults to mb_internal_encoding(). It then returns the initialized object. Throws an InvalidArgumentException if the first argument is an array or object without a __toString method.
public static create ( mixed $str = '', string $encoding = null ) : Stringy
$str mixed Value to modify, after being cast to string
$encoding string The character encoding
Результат Stringy A Stringy object

dasherize() публичный Метод

Returns a lowercase and trimmed string separated by dashes. Dashes are inserted before uppercase characters (with the exception of the first character of the string), and in place of spaces as well as underscores.
public dasherize ( ) : Stringy
Результат Stringy Object with a dasherized $str

delimit() публичный Метод

Delimiters are inserted before uppercase characters (with the exception of the first character of the string), and in place of spaces, dashes, and underscores. Alpha delimiters are not converted to lowercase.
public delimit ( string $delimiter ) : Stringy
$delimiter string Sequence used to separate parts of the string
Результат Stringy Object with a delimited $str

endsWith() публичный Метод

Returns true if the string ends with $substring, false otherwise. By default, the comparison is case-sensitive, but can be made insensitive by setting $caseSensitive to false.
public endsWith ( string $substring, boolean $caseSensitive = true ) : boolean
$substring string The substring to look for
$caseSensitive boolean Whether or not to enforce case-sensitivity
Результат boolean Whether or not $str ends with $substring

ensureLeft() публичный Метод

Ensures that the string begins with $substring. If it doesn't, it's prepended.
public ensureLeft ( string $substring ) : Stringy
$substring string The substring to add if not present
Результат Stringy Object with its $str prefixed by the $substring

ensureRight() публичный Метод

Ensures that the string ends with $substring. If it doesn't, it's appended.
public ensureRight ( string $substring ) : Stringy
$substring string The substring to add if not present
Результат Stringy Object with its $str suffixed by the $substring

first() публичный Метод

Returns the first $n characters of the string.
public first ( integer $n ) : Stringy
$n integer Number of characters to retrieve from the start
Результат Stringy Object with its $str being the first $n chars

getEncoding() публичный Метод

Returns the encoding used by the Stringy object.
public getEncoding ( ) : string
Результат string The current value of the $encoding property

getIterator() публичный Метод

Returns a new ArrayIterator, thus implementing the IteratorAggregate interface. The ArrayIterator's constructor is passed an array of chars in the multibyte string. This enables the use of foreach with instances of Stringy\Stringy.
public getIterator ( ) : ArrayIterator
Результат ArrayIterator An iterator for the characters in the string

hasLowerCase() публичный Метод

Returns true if the string contains a lower case char, false otherwise.
public hasLowerCase ( ) : boolean
Результат boolean Whether or not the string contains a lower case character.

hasUpperCase() публичный Метод

Returns true if the string contains an upper case char, false otherwise.
public hasUpperCase ( ) : boolean
Результат boolean Whether or not the string contains an upper case character.

htmlDecode() публичный Метод

Convert all HTML entities to their applicable characters. An alias of html_entity_decode. For a list of flags, refer to http://php.net/manual/en/function.html-entity-decode.php
public htmlDecode ( integer | null $flags = ENT_COMPAT ) : Stringy
$flags integer | null Optional flags
Результат Stringy Object with the resulting $str after being html decoded.

htmlEncode() публичный Метод

Convert all applicable characters to HTML entities. An alias of htmlentities. Refer to http://php.net/manual/en/function.htmlentities.php for a list of flags.
public htmlEncode ( integer | null $flags = ENT_COMPAT ) : Stringy
$flags integer | null Optional flags
Результат Stringy Object with the resulting $str after being html encoded.

humanize() публичный Метод

Capitalizes the first word of the string, replaces underscores with spaces, and strips '_id'.
public humanize ( ) : Stringy
Результат Stringy Object with a humanized $str

indexOf() публичный Метод

Returns the index of the first occurrence of $needle in the string, and false if not found. Accepts an optional offset from which to begin the search.
public indexOf ( string $needle, integer $offset ) : integer | boolean
$needle string Substring to look for
$offset integer Offset from which to search
Результат integer | boolean The occurrence's index if found, otherwise false

indexOfLast() публичный Метод

Returns the index of the last occurrence of $needle in the string, and false if not found. Accepts an optional offset from which to begin the search. Offsets may be negative to count from the last character in the string.
public indexOfLast ( string $needle, integer $offset ) : integer | boolean
$needle string Substring to look for
$offset integer Offset from which to search
Результат integer | boolean The last occurrence's index if found, otherwise false

insert() публичный Метод

Inserts $substring into the string at the $index provided.
public insert ( string $substring, integer $index ) : Stringy
$substring string String to be inserted
$index integer The index at which to insert the substring
Результат Stringy Object with the resulting $str after the insertion

isAlpha() публичный Метод

Returns true if the string contains only alphabetic chars, false otherwise.
public isAlpha ( ) : boolean
Результат boolean Whether or not $str contains only alphabetic chars

isAlphanumeric() публичный Метод

Returns true if the string contains only alphabetic and numeric chars, false otherwise.
public isAlphanumeric ( ) : boolean
Результат boolean Whether or not $str contains only alphanumeric chars

isBase64() публичный Метод

Returns true if the string is base64 encoded, false otherwise.
public isBase64 ( ) : boolean
Результат boolean Whether or not $str is base64 encoded

isBlank() публичный Метод

Returns true if the string contains only whitespace chars, false otherwise.
public isBlank ( ) : boolean
Результат boolean Whether or not $str contains only whitespace characters

isHexadecimal() публичный Метод

Returns true if the string contains only hexadecimal chars, false otherwise.
public isHexadecimal ( ) : boolean
Результат boolean Whether or not $str contains only hexadecimal chars

isJson() публичный Метод

Returns true if the string is JSON, false otherwise. Unlike json_decode in PHP 5.x, this method is consistent with PHP 7 and other JSON parsers, in that an empty string is not considered valid JSON.
public isJson ( ) : boolean
Результат boolean Whether or not $str is JSON

isLowerCase() публичный Метод

Returns true if the string contains only lower case chars, false otherwise.
public isLowerCase ( ) : boolean
Результат boolean Whether or not $str contains only lower case characters

isSerialized() публичный Метод

Returns true if the string is serialized, false otherwise.
public isSerialized ( ) : boolean
Результат boolean Whether or not $str is serialized

isUpperCase() публичный Метод

Returns true if the string contains only lower case chars, false otherwise.
public isUpperCase ( ) : boolean
Результат boolean Whether or not $str contains only lower case characters

last() публичный Метод

Returns the last $n characters of the string.
public last ( integer $n ) : Stringy
$n integer Number of characters to retrieve from the end
Результат Stringy Object with its $str being the last $n chars

length() публичный Метод

Returns the length of the string. An alias for PHP's mb_strlen() function.
public length ( ) : integer
Результат integer The number of characters in $str given the encoding

lines() публичный Метод

Splits on newlines and carriage returns, returning an array of Stringy objects corresponding to the lines in the string.
public lines ( ) : Stringy[]
Результат Stringy[] An array of Stringy objects

longestCommonPrefix() публичный Метод

Returns the longest common prefix between the string and $otherStr.
public longestCommonPrefix ( string $otherStr ) : Stringy
$otherStr string Second string for comparison
Результат Stringy Object with its $str being the longest common prefix

longestCommonSubstring() публичный Метод

In the case of ties, it returns that which occurs first.
public longestCommonSubstring ( string $otherStr ) : Stringy
$otherStr string Second string for comparison
Результат Stringy Object with its $str being the longest common substring

longestCommonSuffix() публичный Метод

Returns the longest common suffix between the string and $otherStr.
public longestCommonSuffix ( string $otherStr ) : Stringy
$otherStr string Second string for comparison
Результат Stringy Object with its $str being the longest common suffix

lowerCaseFirst() публичный Метод

Converts the first character of the string to lower case.
public lowerCaseFirst ( ) : Stringy
Результат Stringy Object with the first character of $str being lower case

offsetExists() публичный Метод

Returns whether or not a character exists at an index. Offsets may be negative to count from the last character in the string. Implements part of the ArrayAccess interface.
public offsetExists ( mixed $offset ) : boolean
$offset mixed The index to check
Результат boolean Whether or not the index exists

offsetGet() публичный Метод

Returns the character at the given index. Offsets may be negative to count from the last character in the string. Implements part of the ArrayAccess interface, and throws an OutOfBoundsException if the index does not exist.
public offsetGet ( mixed $offset ) : mixed
$offset mixed The index from which to retrieve the char
Результат mixed The character at the specified index

offsetSet() публичный Метод

Implements part of the ArrayAccess interface, but throws an exception when called. This maintains the immutability of Stringy objects.
public offsetSet ( mixed $offset, mixed $value )
$offset mixed The index of the character
$value mixed Value to set

offsetUnset() публичный Метод

Implements part of the ArrayAccess interface, but throws an exception when called. This maintains the immutability of Stringy objects.
public offsetUnset ( mixed $offset )
$offset mixed The index of the character

pad() публичный Метод

Pads the string to a given length with $padStr. If length is less than or equal to the length of the string, no padding takes places. The default string used for padding is a space, and the default type (one of 'left', 'right', 'both') is 'right'. Throws an InvalidArgumentException if $padType isn't one of those 3 values.
public pad ( integer $length, string $padStr = ' ', string $padType = 'right' ) : Stringy
$length integer Desired string length after padding
$padStr string String used to pad, defaults to space
$padType string One of 'left', 'right', 'both'
Результат Stringy Object with a padded $str

padBoth() публичный Метод

Returns a new string of a given length such that both sides of the string are padded. Alias for pad() with a $padType of 'both'.
public padBoth ( integer $length, string $padStr = ' ' ) : Stringy
$length integer Desired string length after padding
$padStr string String used to pad, defaults to space
Результат Stringy String with padding applied

padLeft() публичный Метод

Returns a new string of a given length such that the beginning of the string is padded. Alias for pad() with a $padType of 'left'.
public padLeft ( integer $length, string $padStr = ' ' ) : Stringy
$length integer Desired string length after padding
$padStr string String used to pad, defaults to space
Результат Stringy String with left padding

padRight() публичный Метод

Returns a new string of a given length such that the end of the string is padded. Alias for pad() with a $padType of 'right'.
public padRight ( integer $length, string $padStr = ' ' ) : Stringy
$length integer Desired string length after padding
$padStr string String used to pad, defaults to space
Результат Stringy String with right padding

prepend() публичный Метод

Returns a new string starting with $string.
public prepend ( string $string ) : Stringy
$string string The string to append
Результат Stringy Object with appended $string

regexReplace() публичный Метод

Replaces all occurrences of $pattern in $str by $replacement. An alias for mb_ereg_replace(). Note that the 'i' option with multibyte patterns in mb_ereg_replace() requires PHP 5.6+ for correct results. This is due to a lack of support in the bundled version of Oniguruma in PHP < 5.6, and current versions of HHVM (3.8 and below).
public regexReplace ( string $pattern, string $replacement, string $options = 'msr' ) : Stringy
$pattern string The regular expression pattern
$replacement string The string to replace with
$options string Matching conditions to be used
Результат Stringy Object with the resulting $str after the replacements

removeLeft() публичный Метод

Returns a new string with the prefix $substring removed, if present.
public removeLeft ( string $substring ) : Stringy
$substring string The prefix to remove
Результат Stringy Object having a $str without the prefix $substring

removeRight() публичный Метод

Returns a new string with the suffix $substring removed, if present.
public removeRight ( string $substring ) : Stringy
$substring string The suffix to remove
Результат Stringy Object having a $str without the suffix $substring

repeat() публичный Метод

Returns a repeated string given a multiplier. An alias for str_repeat.
public repeat ( integer $multiplier ) : Stringy
$multiplier integer The number of times to repeat the string
Результат Stringy Object with a repeated str

replace() публичный Метод

Replaces all occurrences of $search in $str by $replacement.
public replace ( string $search, string $replacement ) : Stringy
$search string The needle to search for
$replacement string The string to replace with
Результат Stringy Object with the resulting $str after the replacements

reverse() публичный Метод

Returns a reversed string. A multibyte version of strrev().
public reverse ( ) : Stringy
Результат Stringy Object with a reversed $str

safeTruncate() публичный Метод

Truncates the string to a given length, while ensuring that it does not split words. If $substring is provided, and truncating occurs, the string is further truncated so that the substring may be appended without exceeding the desired length.
public safeTruncate ( integer $length, string $substring = '' ) : Stringy
$length integer Desired length of the truncated string
$substring string The substring to append if it can fit
Результат Stringy Object with the resulting $str after truncating

shuffle() публичный Метод

* A multibyte str_shuffle() function. It returns a string with its characters in random order.
public shuffle ( )

slice() публичный Метод

Returns the substring beginning at $start, and up to, but not including the index specified by $end. If $end is omitted, the function extracts the remaining string. If $end is negative, it is computed from the end of the string.
public slice ( integer $start, integer $end = null ) : Stringy
$start integer Initial index from which to begin extraction
$end integer Optional index at which to end extraction
Результат Stringy Object with its $str being the extracted substring

slugify() публичный Метод

Converts the string into an URL slug. This includes replacing non-ASCII characters with their closest ASCII equivalents, removing remaining non-ASCII and non-alphanumeric characters, and replacing whitespace with $replacement. The replacement defaults to a single dash, and the string is also converted to lowercase.
public slugify ( string $replacement = '-' ) : Stringy
$replacement string The string used to replace whitespace
Результат Stringy Object whose $str has been converted to an URL slug

split() публичный Метод

Splits the string with the provided regular expression, returning an array of Stringy objects. An optional integer $limit will truncate the results.
public split ( string $pattern, integer $limit = null ) : Stringy[]
$pattern string The regex with which to split the string
$limit integer Optional maximum number of results to return
Результат Stringy[] An array of Stringy objects

startsWith() публичный Метод

Returns true if the string begins with $substring, false otherwise. By default, the comparison is case-sensitive, but can be made insensitive by setting $caseSensitive to false.
public startsWith ( string $substring, boolean $caseSensitive = true ) : boolean
$substring string The substring to look for
$caseSensitive boolean Whether or not to enforce case-sensitivity
Результат boolean Whether or not $str starts with $substring

substr() публичный Метод

It differs from the mb_substr() function in that providing a $length of null will return the rest of the string, rather than an empty string.
public substr ( integer $start, integer $length = null ) : Stringy
$start integer Position of the first character to use
$length integer Maximum number of characters used
Результат Stringy Object with its $str being the substring

surround() публичный Метод

Surrounds $str with the given substring.
public surround ( string $substring ) : Stringy
$substring string The substring to add to both sides
Результат Stringy Object whose $str had the substring both prepended and appended

swapCase() публичный Метод

Returns a case swapped version of the string.
public swapCase ( ) : Stringy
Результат Stringy Object whose $str has each character's case swapped

tidy() публичный Метод

Returns a string with smart quotes, ellipsis characters, and dashes from Windows-1252 (commonly used in Word documents) replaced by their ASCII equivalents.
public tidy ( ) : Stringy
Результат Stringy Object whose $str has those characters removed

titleize() публичный Метод

Also accepts an array, $ignore, allowing you to list words not to be capitalized.
public titleize ( array $ignore = null ) : Stringy
$ignore array An array of words not to capitalize
Результат Stringy Object with a titleized $str

toAscii() публичный Метод

Returns an ASCII version of the string. A set of non-ASCII characters are replaced with their closest ASCII counterparts, and the rest are removed unless instructed otherwise.
public toAscii ( boolean $removeUnsupported = true ) : Stringy
$removeUnsupported boolean Whether or not to remove the unsupported characters
Результат Stringy Object whose $str contains only ASCII characters

toBoolean() публичный Метод

For example, 'true', '1', 'on' and 'yes' will return true. 'false', '0', 'off', and 'no' will return false. In all instances, case is ignored. For other numeric strings, their sign will determine the return value. In addition, blank strings consisting of only whitespace will return false. For all other strings, the return value is a result of a boolean cast.
public toBoolean ( ) : boolean
Результат boolean A boolean value for the string

toLowerCase() публичный Метод

Converts all characters in the string to lowercase. An alias for PHP's mb_strtolower().
public toLowerCase ( ) : Stringy
Результат Stringy Object with all characters of $str being lowercase

toSpaces() публичный Метод

Converts each tab in the string to some number of spaces, as defined by $tabLength. By default, each tab is converted to 4 consecutive spaces.
public toSpaces ( integer $tabLength = 4 ) : Stringy
$tabLength integer Number of spaces to replace each tab with
Результат Stringy Object whose $str has had tabs switched to spaces

toTabs() публичный Метод

Converts each occurrence of some consecutive number of spaces, as defined by $tabLength, to a tab. By default, each 4 consecutive spaces are converted to a tab.
public toTabs ( integer $tabLength = 4 ) : Stringy
$tabLength integer Number of spaces to replace with a tab
Результат Stringy Object whose $str has had spaces switched to tabs

toTitleCase() публичный Метод

Converts the first character of each word in the string to uppercase.
public toTitleCase ( ) : Stringy
Результат Stringy Object with all characters of $str being title-cased

toUpperCase() публичный Метод

Converts all characters in the string to uppercase. An alias for PHP's mb_strtoupper().
public toUpperCase ( ) : Stringy
Результат Stringy Object with all characters of $str being uppercase

trim() публичный Метод

Returns a string with whitespace removed from the start and end of the string. Supports the removal of unicode whitespace. Accepts an optional string of characters to strip instead of the defaults.
public trim ( string $chars = null ) : Stringy
$chars string Optional string of characters to strip
Результат Stringy Object with a trimmed $str

trimLeft() публичный Метод

Supports the removal of unicode whitespace. Accepts an optional string of characters to strip instead of the defaults.
public trimLeft ( string $chars = null ) : Stringy
$chars string Optional string of characters to strip
Результат Stringy Object with a trimmed $str

trimRight() публичный Метод

Supports the removal of unicode whitespace. Accepts an optional string of characters to strip instead of the defaults.
public trimRight ( string $chars = null ) : Stringy
$chars string Optional string of characters to strip
Результат Stringy Object with a trimmed $str

truncate() публичный Метод

Truncates the string to a given length. If $substring is provided, and truncating occurs, the string is further truncated so that the substring may be appended without exceeding the desired length.
public truncate ( integer $length, string $substring = '' ) : Stringy
$length integer Desired length of the truncated string
$substring string The substring to append if it can fit
Результат Stringy Object with the resulting $str after truncating

underscored() публичный Метод

Underscores are inserted before uppercase characters (with the exception of the first character of the string), and in place of spaces as well as dashes.
public underscored ( ) : Stringy
Результат Stringy Object with an underscored $str

upperCamelize() публичный Метод

Returns an UpperCamelCase version of the supplied string. It trims surrounding spaces, capitalizes letters following digits, spaces, dashes and underscores, and removes spaces, dashes, underscores.
public upperCamelize ( ) : Stringy
Результат Stringy Object with $str in UpperCamelCase

upperCaseFirst() публичный Метод

Converts the first character of the supplied string to upper case.
public upperCaseFirst ( ) : Stringy
Результат Stringy Object with the first character of $str being upper case

Описание свойств

$encoding защищенное свойство

The string's encoding, which should be one of the mbstring module's supported encodings.
protected string $encoding
Результат string

$str защищенное свойство

An instance's string.
protected string $str
Результат string