Skip to content

Latest commit

 

History

History
486 lines (355 loc) · 11.6 KB

File metadata and controls

486 lines (355 loc) · 11.6 KB

str

  • class str (php\lib\str)
  • package std
  • source php/lib/Str.php

Description

Class str


Static Methods

  • str ::pos() - Returns the index within this string of the first occurrence of the
  • str ::posIgnoreCase() - The same method as pos() only with ignoring case characters
  • str ::lastPos() - Returns the index within this string of the last occurrence of the
  • str ::lastPosIgnoreCase() - The same method as lastPos() only with ignoring case characters
  • str ::sub() - Returns a new string that is a substring of this string. The
  • str ::compare() - Compares two strings lexicographically.
  • str ::compareIgnoreCase() - The same method as compare() only with ignoring case characters
  • str ::equalsIgnoreCase() - Checks that the strings are equal with ignoring case characters
  • str ::startsWith() - Tests if the substring of this string beginning at the
  • str ::endsWith() - Tests if this string ends with the specified suffix.
  • str ::lower() - Converts all of the characters in $string to lower
  • str ::upper() - Converts all of the characters in $string to upper
  • str ::length() - Returns the length of $string.
  • str ::replace() - Replaces each substring of this string that matches the literal target
  • str ::repeat() - Return s a new string consisting of the original $string repeated
  • str ::trim() - Returns a copy of the string, with leading and trailing whitespace
  • str ::trimRight()
  • str ::trimLeft()
  • str ::reverse() - Reverse the string.
  • str ::shuffle() - Returns a randomized string based on chars in $string
  • str ::random() - Returns a new random string based on set.
  • str ::split() - The method like explode() in Zend PHP.
  • str ::join() - The method like implode() in Zend PHP.
  • str ::encode() - Converts $string by using $charset and returns a binary string.
  • str ::decode() - Decodes $string by using $charset to UNICODE, returns a unicode string.
  • str ::isNumber() - Returns true if $string is integer number (e.g: '12893', '3784', '0047')
  • str ::isLower()
  • str ::isUpper()
  • str ::lowerFirst()
  • str ::upperFirst()
  • str ::parseAs() - Parse text as json, ini, yaml, etc.
  • str ::formatAs() - Format value as ini, json, yml, etc.
  • str ::format()
  • str ::contains() - Returns true if string contains a substring.
  • str ::count() - Возвращает количество найденный строк в другой строке.
  • str ::uuid()
  • str ::hash() - Возвращает хеш строки.
  • str ::lines() - Переводит многострочный текст в массив, если $removeEmpty true, то удаляет пустые строки из результата.

Methods


Static Methods

pos()

str::pos(string $string, string $search, int $fromIndex): int

Returns the index within this string of the first occurrence of the specified substring, starting at the specified index.


posIgnoreCase()

str::posIgnoreCase(string $string, string $search, int $fromIndex): int

The same method as pos() only with ignoring case characters


lastPos()

str::lastPos(string $string, string $search, null|int $fromIndex): int

Returns the index within this string of the last occurrence of the specified substring. The last occurrence of the empty string "" is considered to occur at the index value $string.length.


lastPosIgnoreCase()

str::lastPosIgnoreCase(string $string, string $search, null|int $fromIndex): int

The same method as lastPos() only with ignoring case characters


sub()

str::sub(string $string, int $beginIndex, null|int $endIndex): string

Returns a new string that is a substring of this string. The substring begins at the specified $beginIndex and extends to the character at index $endIndex - 1. Thus the length of the substring is endIndex - beginIndex.


compare()

str::compare(string $string1, string $string2): int

Compares two strings lexicographically. The comparison is based on the Unicode value of each character in the strings.

The character sequence represented by $string1 String is compared lexicographically to the character sequence represented by $string2. The result is a negative integer if $string1 lexicographically precedes $string2. The result is a positive integer if $string1 lexicographically follows $string2. The result is zero if the strings are equal; compare returns 0 exactly when the strings are equal


compareIgnoreCase()

str::compareIgnoreCase(string $string1, string $string2): int

The same method as compare() only with ignoring case characters


equalsIgnoreCase()

str::equalsIgnoreCase(string $string1, string $string2): bool

Checks that the strings are equal with ignoring case characters


startsWith()

str::startsWith(string $string, string $prefix, int $offset): bool

Tests if the substring of this string beginning at the specified index starts with the specified prefix.

Returns true if the character sequence represented by the argument is a prefix of the substring of this object starting at index offset; false otherwise. The result is false if toffset is negative or greater than the length of this $string; otherwise the result is the same as the result of the expression

.. code-block:: php

startsWith(sub($offset), $prefix)


endsWith()

str::endsWith(string $string, string $suffix): bool

Tests if this string ends with the specified suffix.


lower()

str::lower(string $string): string

Converts all of the characters in $string to lower case using the rules of the default locale.


upper()

str::upper(string $string): string

Converts all of the characters in $string to upper case using the rules of the default locale.


length()

str::length(string $string): int

Returns the length of $string. The length is equal to the number of Unicode code units in the string.


replace()

str::replace(string $string, string $target, string $replacement): string

Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence. The replacement proceeds from the beginning of the string to the end, for example, replacing "aa" with "b" in the string "aaa" will result in "ba" rather than "ab".


repeat()

str::repeat(string $string, int $amount): string

Return s a new string consisting of the original $string repeated


trim()

str::trim(string $string, string $charList): string

Returns a copy of the string, with leading and trailing whitespace omitted.


trimRight()

str::trimRight(string $string, string $charList): string

trimLeft()

str::trimLeft(string $string, string $charList): string

reverse()

str::reverse(string $string): string

Reverse the string.


shuffle()

str::shuffle(string $string): string

Returns a randomized string based on chars in $string


random()

str::random(int $length, string $set): string

Returns a new random string based on set.


split()

str::split(string $string, string $separator, int $limit): array

The method like explode() in Zend PHP.


join()

str::join(array|\Iterator $iterable, string $separator, int $limit): string

The method like implode() in Zend PHP.


encode()

str::encode(string $string, string $charset): string

Converts $string by using $charset and returns a binary string.


decode()

str::decode(string $string, string $charset): string

Decodes $string by using $charset to UNICODE, returns a unicode string.


isNumber()

str::isNumber(string $string, bool $bigNumbers): bool

Returns true if $string is integer number (e.g: '12893', '3784', '0047')

  • for 123 - true
  • for 00304 - true
  • for 3389e4 - false
  • for 3.49 - false
  • for 23 - false

isLower()

str::isLower(string $string): bool

isUpper()

str::isUpper(mixed $string): bool

lowerFirst()

str::lowerFirst(string $string): string

upperFirst()

str::upperFirst(string $string): string

parseAs()

str::parseAs(string $string, string $format, int $flags): mixed

Parse text as json, ini, yaml, etc.


formatAs()

str::formatAs(mixed $input, string $format, int $flags): string

Format value as ini, json, yml, etc.


format()

str::format(string $string, mixed $args): string

contains()

str::contains(string $string, string $search): bool

Returns true if string contains a substring.


count()

str::count(string $string, string $subString, int $offset): int

Возвращает количество найденный строк в другой строке.


uuid()

str::uuid(null|string $value): string

hash()

str::hash(string $string, string $algorithm): string

Возвращает хеш строки.


lines()

str::lines(string $string, bool $removeEmpty): array

Переводит многострочный текст в массив, если $removeEmpty true, то удаляет пустые строки из результата.


Methods

__construct()

__construct(): void