Méthode |
Description |
|
__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. |
|