kexxt/php-string-helpers

Helpful string functions

v1.0.2 2020-08-23 19:32 UTC

This package is not auto-updated.

Last update: 2024-04-29 02:27:10 UTC


README

=============

String helper functions wrapped into an easy to use class

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist go-redrock/php-string/helpers "*"

or add

"go-redrock/php-string/helpers": "*"

to the require section of your composer.json file.

Usage

\Trac\Helper\Strings\Str

VisibilityFunction
public staticafter(string $subject, string $search) : string
Return the remainder of a string after the first occurrence of a given value.
public staticafterLast(string $subject, string $search) : string
Return the remainder of a string after the last occurrence of a given value.
public staticascii(string $value, string $language='en') : string
Transliterate a UTF-8 value to ASCII.
public staticbefore(string $subject, string $search) : string
Get the portion of a string before the first occurrence of a given value.
public staticbeforeLast(string $subject, string $search) : string
Get the portion of a string before the last occurrence of a given value.
public staticbetween(string $subject, string $from, string $to) : string
Get the portion of a string between two given values.
public staticcamel(string $value) : string
Convert a value to camel case.
public staticcontains(string $haystack, string/string[] $needles) : bool
Determine if a given string contains a given substring.
public staticcontainsAll(string $haystack, string[] $needles) : bool
Determine if a given string contains all array values.
public staticendsWith(string $haystack, string/string[] $needles) : bool
Determine if a given string ends with a given substring.
public staticfinish(string $value, string $cap) : string
Cap a string with a single instance of a given value.
public staticis(string/array $pattern, \string $value) : bool
Determine if a given string matches a given pattern.
public staticisAscii(string $value) : bool
Determine if a given string is 7 bit ASCII.
public staticisUuid(string $value) : bool
Determine if a given string is a valid UUID.
public statickebab(string $value) : string
Convert a string to kebab case.
public staticlength(string $value, string/null $encoding=null) : int
Return the length of the given string.
public staticlimit(string $value, int $limit=100, string $end='...') : string
Limit the number of characters in a string.
public staticlower(string $value) : string
Convert the given string to lower-case.
public staticorderedUuid() : \Ramsey\Uuid\UuidInterface
Generate a time-ordered UUID (version 4).
public staticrandom(int $length=16) : string
Generate a more truly "random" alpha-numeric string.
public staticreplace(string $search, string $replace, string $subject) : string
Replace all occurrences of a given value in the string.
public staticreplaceArray(string $search, array $replace, string $subject) : string
Replace a given value in the string sequentially with an array.
public staticreplaceFirst(string $search, string $replace, string $subject) : string
Replace the first occurrence of a given value in the string.
public staticreplaceLast(string $search, string $replace, string $subject) : string
Replace the last occurrence of a given value in the string.
public staticslug(string $title, string $separator='-', string/string/null $language='en') : string
Generate a URL friendly "slug" from a given string.
public staticsnake(string $value, string $delimiter='_') : string
Convert a string to snake case.
public staticstart(string $value, string $prefix) : string
Begin a string with a single instance of a given value.
public staticstartsWith(string $haystack, string/string[] $needles) : bool
Determine if a given string starts with a given substring.
public staticstudly(string $value) : string
Convert a value to studly caps case.
public staticsubstr(string $string, int $start, int/null $length=null) : string
Returns the portion of string specified by the start and length parameters.
public staticsubstrCount(string $haystack, string $needle, int $offset, int/null $length=null) : int
Returns the number of substring occurrences.
public statictitle(string $value) : string
Convert the given string to title case.
public staticucfirst(string $string) : string
Make a string's first character uppercase.
public staticupper(string $value) : string
Convert the given string to upper-case.
public staticuuid() : \Ramsey\Uuid\UuidInterface
Generate a UUID (version 4).
public staticwords(string $value, int $words=100, string $end='...') : string
Limit the number of words in a string.