{"id":27185947,"url":"https://github.com/bdusell/jitsu-string","last_synced_at":"2025-04-09T17:55:37.060Z","repository":{"id":56999484,"uuid":"42752300","full_name":"bdusell/jitsu-string","owner":"bdusell","description":"A better API for PHP's string functions","archived":false,"fork":false,"pushed_at":"2016-05-07T07:59:08.000Z","size":34,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-24T11:55:54.046Z","etag":null,"topics":["escape","helper-functions","php","string"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bdusell.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-18T23:53:44.000Z","updated_at":"2017-10-17T21:18:55.000Z","dependencies_parsed_at":"2022-08-21T13:50:58.035Z","dependency_job_id":null,"html_url":"https://github.com/bdusell/jitsu-string","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bdusell%2Fjitsu-string","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bdusell%2Fjitsu-string/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bdusell%2Fjitsu-string/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bdusell%2Fjitsu-string/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bdusell","download_url":"https://codeload.github.com/bdusell/jitsu-string/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248083590,"owners_count":21045122,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["escape","helper-functions","php","string"],"created_at":"2025-04-09T17:55:31.937Z","updated_at":"2025-04-09T17:55:37.052Z","avatar_url":"https://github.com/bdusell.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"jitsu/string\n------------\n\nThe `Jitsu\\StringUtil` class is a collection of static methods for dealing with\nstrings in PHP.\n\nWhy? Because many of PHP's built-in string functions are poorly named, have\nawkward interfaces, and treat arguably valid edge cases as errors.\n\n`StringUtil` addresses these issues, providing a more intuitive interface to\nthe standard PHP string functions while offering capabilities which are lacking\nin the built-in library.\n\nThis package is part of [Jitsu](https://github.com/bdusell/jitsu).\n\n## Installation\n\nInstall this package with [Composer](https://getcomposer.org/):\n\n```sh\ncomposer require jitsu/string\n```\n\n## Testing\n\nRun the unit test suite as follows:\n\n```sh\ncomposer install\n./vendor/bin/phpunit test/\n```\n\n## Namespace\n\nThe class is defined under the namespace `Jitsu`.\n\n## API\n\n### class Jitsu\\\\StringUtil\n\nA collection of static methods for dealing with strings.\n\nCase-insensitive methods are named after their case-sensitive counterparts\nby prefixing the letter `i`.\n\n#### StringUtil::length($s)\n\nReturn the length of a string.\n\nThis is equivalent to the number of bytes in the string.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `int` |\n\n#### StringUtil::size($s)\n\nAlias of `length`. See `\\Jitsu\\StringUtil::length()`.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `int` |\n\n#### StringUtil::isEmpty($s)\n\nDetermine whether a string is empty.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `bool` |\n\n#### StringUtil::equal($a, $b)\n\nReturn whether two strings are equal.\n\n|   | Type |\n|---|------|\n| **`$a`** | `string` |\n| **`$b`** | `string` |\n| returns | `bool` |\n\n#### StringUtil::iEqual($a, $b)\n\nLike `equal` but case-insensitive.\n\n|   | Type |\n|---|------|\n| **`$a`** | `string` |\n| **`$b`** | `string` |\n| returns | `bool` |\n\n#### StringUtil::chars($s)\n\nReturn the characters of a string as an array.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `string[]` |\n\n#### StringUtil::chunks($s, $n)\n\nSplit a string into chunks of `$n` characters.\n\nEach chunk is a sequential array. The last chunk may have between 1\nand `$n` characters.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `string[]` |\n\n#### StringUtil::split($s, $delim = null, $limit = null)\n\nSplit a string by a delimiter into an array of strings.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| **`$delim`** | `string|null` | An optional delimiter string. If this is `null`, the string is tokenized on whitespace characters rather than on a specific delimiter string. |\n| **`$limit`** | `int|null` | An optional maximum number of splits to perform. If this is `null`, then all possible splits are made. If this is a positive integer, at most `$limit` splits will be made from the beginning of the string, with the rest of the string occupying the last element, so that no more than `$limit` + 1 elements will be returned. If `$limit` is negative, all parts except for the last -`$limit` are returned. This is ignored if `$delim` is `null`. |\n| returns | `string[]` |  |\n\n#### StringUtil::tokenize($s, $chars)\n\nSplit a string into tokens.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| **`$chars`** | `string` | A string listing the delimiting characters. |\n| returns | `string[]` |  |\n\n#### StringUtil::join($sep, $strs = null)\n\nJoin array elements into a single string with a separator.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$sep`** | `string` | The separator string. |\n| **`$strs`** | `string[]` | The list of strings. |\n| returns | `string` |  |\n\n#### StringUtil::trim($s, $chars = null)\n\nStrip characters from the beginning and end of a string.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| **`$chars`** | `string|null` | An optional string listing the characters to strip. If this is `null`, then whitespace and null bytes are stripped. |\n| returns | `string` |  |\n\n#### StringUtil::rtrim($s, $chars = null)\n\nStrip characters from the end of a string.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| **`$chars`** | `string|null` |\n| returns | `string` |\n\n#### StringUtil::ltrim($s, $chars = null)\n\nStrip characters from the beginning of a string.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| **`$chars`** | `string|null` |\n| returns | `string` |\n\n#### StringUtil::lower($s)\n\nConvert a string to lower case.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `string` |\n\n#### StringUtil::upper($s)\n\nConvert a string to upper case.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `string` |\n\n#### StringUtil::lcfirst($s)\n\nConvert a string's first character to lower case.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `string` |\n\n#### StringUtil::lowerFirst($s)\n\nAlias for `lcfirst`. See `\\Jitsu\\StringUtil::lcfirst()`.\n\n#### StringUtil::ucfirst($s)\n\nConvert a string's first character to upper case.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `string` |\n\n#### StringUtil::upperFirst($s)\n\nAlias for `ucfirst`. See `\\Jitsu\\StringUtil::ucfirst()`.\n\n#### StringUtil::capitalize($s)\n\nAlias for `ucfirst`. See `\\Jitsu\\StringUtil::ucfirst()`.\n\n#### StringUtil::ucwords($s)\n\nCapitalize all words in a string.\n\nConverts any alphabetic character that appears after whitespace to\nupper case.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `string` |\n\n#### StringUtil::capitalizeWords($s)\n\nAlias for `ucwords`. See `\\Jitsu\\StringUtil::ucwords()`.\n\n#### StringUtil::replace($s, $old, $new)\n\nReplace all instances of a substring with another.\n\nReplaces only non-overlapping instances of the substring.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| **`$old`** | `string` |\n| **`$new`** | `string` |\n| returns | `string` |\n\n#### StringUtil::replaceAndCount($s, $old, $new)\n\nReplace a string and return the number of replacements.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| **`$old`** | `string` |  |\n| **`$new`** | `string` |  |\n| returns | `array` | The pair `array($result, $count)`. |\n\n#### StringUtil::iReplace($s, $old, $new)\n\nLike `replace` but case-insensitive.\n\nSee `\\Jitsu\\StringUtil::replace()`.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| **`$old`** | `string` |\n| **`$new`** | `string` |\n| returns | `string` |\n\n#### StringUtil::iReplaceAndCount($s, $old, $new)\n\nLike `replaceAndCount` but case-insensitive.\n\nSee `\\Jitsu\\StringUtil::replaceAndCount()`.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| **`$old`** | `string` |  |\n| **`$new`** | `string` |  |\n| returns | `array` | The pair `array($result, $count)`. |\n\n#### StringUtil::replaceMultiple($s, $pairs)\n\nPeform multiple substring replacements at once.\n\nAllows one to perform multiple replacements at once, which may be a\nbetter alternative to performing successive single-string\nreplacements.\n\nReplaces all non-overlapping instances of the keys of `$pairs` with\ntheir corresponding values.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| **`$pairs`** | `string[]` | An array mapping the substrings to be replaced to their replacements. Longer keys have precedence. |\n| returns | `string` |  |\n\n#### StringUtil::translate($s, $old, $new)\n\nRe-map the characters in a string.\n\nCharacters listed in `$old` are changed to the corresponding\ncharacters listed in `$new`.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| **`$old`** | `string` |\n| **`$new`** | `string` |\n| returns | `string` |\n\n#### StringUtil::substring($s, $offset, $length = null)\n\nGet a substring of a string given an offset and length.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| **`$offset`** | `int` | The offset at which to begin the substring. If greater than the length of the string, the result will be an empty string. A negative offset denotes an offset from the end of the string. |\n| **`$length`** | `int|null` | The length of the substring. The resulting substring will be shorter if the specified length runs past the end of the string. If negative, an empty string will be returned. If `null`, the substring will run to the end of the string. |\n| returns | `string` |  |\n\n#### StringUtil::replaceSubstring($s, $new, $offset, $length = null)\n\nReplace a portion of a string with another.\n\nSee `\\Jitsu\\StringUtil::replace()`.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| **`$new`** | `string` | The replacement string. |\n| **`$offset`** | `int` |  |\n| **`$length`** | `int|null` |  |\n| returns | `string` |  |\n\n#### StringUtil::slice($s, $i, $j = null)\n\nGet a slice of string given two offsets.\n\nGets a substring of a string given an inclusive beginning index and\na non-inclusive ending index. Negative indexes denote offsets from\nthe end of the string.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| **`$i`** | `int` | If this occurs after the end index, an empty string is returned. |\n| **`$j`** | `int|null` | If `null`, the slice runs to the end of the string. |\n| returns | `string` |  |\n\n#### StringUtil::replaceSlice($s, $new, $i, $j = null)\n\nReplace a slice of a string with another string.\n\nIf the starting index comes after the ending index, the replacement\nis inserted at the starting index.\n\nSee `\\Jitsu\\StringUtil::slice()`.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| **`$new`** | `string` |\n| **`$i`** | `int` |\n| **`$j`** | `int|null` |\n| returns | `string` |\n\n#### StringUtil::insert($s, $new, $offset)\n\nInsert a string at a given offset in another string.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| **`$new`** | `string` |  |\n| **`$offset`** | `int` | A negative offset denotes an offset from the end of the string. |\n| returns | `string` |  |\n\n#### StringUtil::pad($s, $n, $pad = ' ')\n\nPad the beginning and end of a string with another string.\n\nSymmetrically pads a string with another so that the result is `$n`\ncharacters long.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| **`$n`** | `int` |\n| **`$pad`** | `string` |\n| returns | `string` |\n\n#### StringUtil::lpad($s, $n, $pad = ' ')\n\nPad the beginning of a string with another string.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| **`$n`** | `int` |\n| **`$pad`** | `string` |\n| returns | `string` |\n\n#### StringUtil::rpad($s, $n, $pad = ' ')\n\nPad the end of a string with another string.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| **`$n`** | `int` |\n| **`$pad`** | `string` |\n| returns | `string` |\n\n#### StringUtil::wrap($s, $cols, $sep = \"\\\\n\")\n\nWrap a string to a certain number of columns.\n\nThis \"wraps\" a string to a fixed number of columns by inserting a\nstring every `$cols` characters. Inserts newlines by default.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| **`$cols`** | `int` |\n| **`$sep`** | `string` |\n| returns | `string` |\n\n#### StringUtil::repeat($s, $n)\n\nRepeat a string `$n` times.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| **`$n`** | `int` |\n| returns | `string` |\n\n#### StringUtil::reverse($s)\n\nReverse a string.\n\n@param string\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n\n#### StringUtil::startingWith($s, $substr)\n\nReturn the part of a string starting with another string.\n\nThe result includes the specified substring.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| **`$substr`** | `string` |  |\n| returns | `string|null` | Returns `null` if the string does not contain the substring. |\n\n#### StringUtil::iStartingWith($s, $substr)\n\nLike `startingWith` but case-insenstive.\n\nSee `\\Jitsu\\StringUtil::startingWith()`.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| **`$substr`** | `string` |\n| returns | `string|null` |\n\n#### StringUtil::rStartingWith($s, $char)\n\nReturn the last part of a string starting with a certain character.\n\nUnlike `startingWith`, this only works for single characters.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| **`$char`** | `string` | A single character. |\n| returns | `string|null` | Returns `null` if the string does not contain the character. |\n\n#### StringUtil::startingWithChars($s, $chars)\n\nReturn the last part of a string to start with one of a number of\ncharacters.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| **`$chars`** | `string` | Lists the characters to look for. |\n| returns | `string|null` | Returns `null` if none of the characters were found. |\n\n#### StringUtil::preceding($s, $substr)\n\nReturn the part of a string up until a certain substring.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| **`$substr`** | `string` |  |\n| returns | `string|null` | Returns `null` if the string does not contain the substring. |\n\n#### StringUtil::iPreceding($s, $substr)\n\nLike `preceding` but case-insensitive.\n\nSee `\\Jitsu\\StringUtil::preceding()`.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| **`$substr`** | `string` |\n| returns | `string|null` |\n\n#### StringUtil::words($s, $chars = null)\n\nSplit a string into words.\n\nWhat constitutes a word character is defined by the current locale.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| **`$chars`** | `string|null` | An optional list of additional characters to consider as word characters. |\n| returns | `string[]` |  |\n\n#### StringUtil::wordCount($s, $chars = null)\n\nCount the number of words in a string.\n\nSee `\\Jitsu\\StringUtil::words()`.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| **`$chars`** | `string|null` |\n| returns | `int` |\n\n#### StringUtil::findWords($s, $chars = null)\n\nLocate the words in a string.\n\nReturns an array mapping the starting indexes of the words in the\nstring to their corresponding words.\n\nSee `\\Jitsu\\StringUtil::words()`.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| **`$chars`** | `string|null` |\n| returns | `string[]` |\n\n#### StringUtil::wordWrap($s, $width, $sep = \"\\\\n\")\n\nWord-wrap a string.\n\nWord-wraps a string to a fixed number of columns. Words longer than\nthe maximum width are split.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| **`$width`** | `int` |  |\n| **`$sep`** | `string` | Optionally provide a character other than newline to terminate lines. |\n| returns | `string` |  |\n\n#### StringUtil::compare($a, $b)\n\nLexicographically compare two strings.\n\nReturns a negative number if `$a` comes before `$b`, 0 if they are\nthe same, and a number greater than 0 if `$a` comes after `$b`.\n\n|   | Type |\n|---|------|\n| **`$a`** | `string` |\n| **`$b`** | `string` |\n| returns | `int` |\n\n#### StringUtil::iCompare($a, $b)\n\nLike `compare` but case-insensitive.\n\nSee `\\Jitsu\\StringUtil::compare()`.\n\n|   | Type |\n|---|------|\n| **`$a`** | `string` |\n| **`$b`** | `string` |\n| returns | `int` |\n\n#### StringUtil::nCompare($a, $b, $n)\n\nLike `compare` but only checks the first `$n` characters.\n\nSee `\\Jitsu\\StringUtil::compare()`.\n\n|   | Type |\n|---|------|\n| **`$a`** | `string` |\n| **`$b`** | `string` |\n| **`$n`** | `int` |\n| returns | `int` |\n\n#### StringUtil::inCompare($a, $b, $n)\n\nLike `nCompare` but case-insensitive.\n\nSee `\\Jitsu\\StringUtil::nCompare()`.\n\n|   | Type |\n|---|------|\n| **`$a`** | `string` |\n| **`$b`** | `string` |\n| **`$n`** | `int` |\n| returns | `int` |\n\n#### StringUtil::localeCompare($a, $b)\n\nLike `compare` but dependent on the current locale.\n\nSee `\\Jitsu\\StringUtil::compare()`.\n\n|   | Type |\n|---|------|\n| **`$a`** | `string` |\n| **`$b`** | `string` |\n| returns | `int` |\n\n#### StringUtil::humanCompare($a, $b)\n\nLike `compare` but uses a human-sensible comparison.\n\nOrders strings in a way that seems more natural for human viewers\n(numbers are sorted in increasing order, etc.).\n\nSee `\\Jitsu\\StringUtil::compare()`.\n\n|   | Type |\n|---|------|\n| **`$a`** | `string` |\n| **`$b`** | `string` |\n| returns | `int` |\n\n#### StringUtil::iHumanCompare($a, $b)\n\nLike `humanCompare` but case-insensitive.\n\nSee `\\Jitsu\\StringUtil::humanCompare()`.\n\n|   | Type |\n|---|------|\n| **`$a`** | `string` |\n| **`$b`** | `string` |\n| returns | `int` |\n\n#### StringUtil::substringCompare($a, $b, $offset, $length = null)\n\nLike `compare` but uses only a substring of the first string.\n\nSee `\\Jitsu\\StringUtil::compare()`.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$a`** | `string` |  |\n| **`$offset`** | `int` | Starting offset of where comparison with `$a` should start. A negative offset counts from the end of the string. |\n| **`$length`** | `int|null` | Maximum length of the portion of `$a` used in the comparison. If `null`, comparison is until the of the string. |\n| returns | `int` |  |\n\n#### StringUtil::iSubstringCompare($a, $b, $offset, $length = null)\n\nLike `substringCompare` but case-insensitive.\n\nSee `\\Jitsu\\StringUtil::substringCompare()`.\n\n|   | Type |\n|---|------|\n| **`$a`** | `string` |\n| **`$offset`** | `int` |\n| **`$length`** | `int|null` |\n| **`$b`** | `string` |\n| returns | `int` |\n\n#### StringUtil::contains($s, $substr, $offset = 0)\n\nDetermine whether a string contains a certain substring.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| **`$substr`** | `string` |  |\n| **`$offset`** | `int` | Optionally provide a starting offset. |\n| returns | `bool` |  |\n\n#### StringUtil::iContains($s, $substr, $offset = 0)\n\nLike `contains` but case-insensitive.\n\nSee `\\Jitsu\\StringUtil::contains()`.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| **`$substr`** | `string` |\n| **`$offset`** | `int` |\n| returns | `bool` |\n\n#### StringUtil::containsChars($s, $chars)\n\nDetermine whether a string includes one of a number of characters.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| **`$chars`** | `string` | A list of characters. |\n| returns | `bool` |  |\n\n#### StringUtil::containsChar($s, $char)\n\nDetermine whether a string contains a character.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| **`$char`** | `string` | A single character. |\n| returns | `bool` |  |\n\n#### StringUtil::beginsWith($s, $prefix)\n\nDetermine whether a string begins with a certain prefix.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| **`$prefix`** | `string` |\n| returns | `bool` |\n\n#### StringUtil::iBeginsWith($s, $prefix)\n\nLike `beginsWith` but case-insensitive.\n\nSee `\\Jitsu\\StringUtil::beginsWith()`.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| **`$prefix`** | `string` |\n| returns | `bool` |\n\n#### StringUtil::endsWith($s, $suffix)\n\nDetermine whether a string ends with a certain suffix.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| **`$suffix`** | `string` |\n| returns | `bool` |\n\n#### StringUtil::iEndsWith($s, $suffix)\n\nLike `endsWith` but case-insensitive.\n\nSee `\\Jitsu\\StringUtil::endsWith()`.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| **`$suffix`** | `string` |\n| returns | `bool` |\n\n#### StringUtil::removePrefix($s, $prefix)\n\nRemove a prefix from a string.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| **`$prefix`** | `string` |  |\n| returns | `string|null` | Returns `null` if the subject string does not have the prefix. |\n\n#### StringUtil::iRemovePrefix($s, $prefix)\n\nLike `removePrefix`, but case-insensitive.\n\nSee `\\Jitsu\\StringUtil::removePrefix()`.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| **`$prefix`** | `string` |\n| returns | `string|null` |\n\n#### StringUtil::removeSuffix($s, $suffix)\n\nRemove a suffix from a string.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| **`$suffix`** | `string` |  |\n| returns | `string|null` | Returns `null` if the subject string does not have the suffix. |\n\n#### StringUtil::iRemoveSuffix($s, $suffix)\n\nLike `removeSuffix`, but case-insensitive.\n\nSee `\\Jitsu\\StringUtil::removeSuffix()`.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| **`$suffix`** | `string` |\n| returns | `string|null` |\n\n#### StringUtil::find($s, $substr, $offset = 0)\n\nDetermine the location of a substring within another string.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| **`$substr`** | `string` |  |\n| **`$offset`** | `int` | Optionally provide a starting offset. |\n| returns | `int|null` | The starting index of the substring, or `null` if the substring does not appear within the string. |\n\n#### StringUtil::iFind($s, $substr, $offset = 0)\n\nLike `find` but case-insensitive.\n\nSee `\\Jitsu\\StringUtil::find()`.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| **`$substr`** | `string` |\n| **`$offset`** | `int` |\n| returns | `int|null` |\n\n#### StringUtil::rFind($s, $substr, $offset = 0)\n\nLike `find` but starts from the end of the string.\n\nSee `\\Jitsu\\StringUtil::find()`.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| **`$substr`** | `string` |  |\n| **`$offset`** | `int` | The optional offset is the number of characters from the _end_ of the string. |\n| returns | `int|null` |  |\n\n#### StringUtil::before($s, $substr)\n\nGet the part of a string before a certain substring.\n\nReturns the whole string if it does not contain the substring.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| **`$substr`** | `string` |\n| returns | `string` |\n\n#### StringUtil::after($s, $substr)\n\nGet the part of a string after the last occurrence of a certain\nsubstring.\n\nReturns the whole string if it does not contain that substring.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| **`$substr`** | `string` |\n| returns | `string` |\n\n#### StringUtil::isLower($s)\n\nDetermine whether all characters in a string are lower case.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| returns | `bool` | Returns `false` if `$s` is empty. |\n\n#### StringUtil::isUpper($s)\n\nDetermine whether all characters in a string are upper case.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| returns | `bool` | Returns `false` if `$s` is empty. |\n\n#### StringUtil::isAlphanumeric($s)\n\nDetermine whether all characters in a string are alphanumeric.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| returns | `bool` | Returns `false` if `$s` is empty. |\n\n#### StringUtil::isAlphabetic($s)\n\nDetermine whether all characters in a string are alphabetic.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| returns | `bool` | Returns `false` if `$s` is empty. |\n\n#### StringUtil::isControl($s)\n\nDetermine whether all characters in a string are control characters.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| returns | `bool` | Returns `false` if `$s` is empty. |\n\n#### StringUtil::isDecimal($s)\n\nDetermine whether all characters in a string are decimal digits.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| returns | `bool` | Returns `false` if `$s` is empty. |\n\n#### StringUtil::isHex($s)\n\nDetermine whether all characters in a string are hexadecimal digits.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| returns | `bool` | Returns `false` if `$s` is empty. |\n\n#### StringUtil::isVisible($s)\n\nDetermine whether all characters in a string are visible characters.\n\nWhitespace and control characters are not visible characters.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| returns | `bool` | Returns `false` if `$s` is empty. |\n\n#### StringUtil::isPrintable($s)\n\nDetermine whether all characters in a string have printable output.\n\nControl characters do not have printable output.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| returns | `bool` | Returns `false` if `$s` is empty. |\n\n#### StringUtil::isPunctuation($s)\n\nDetermine whether all characters in a string are punctuation.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| returns | `bool` | Returns `false` if `$s` is empty. |\n\n#### StringUtil::isWhitespace($s)\n\nDetermine whether all characters in a string are whitespace.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| returns | `bool` | Returns `false` if `$s` is empty. |\n\n#### StringUtil::count($s, $substr, $offset = 0, $length = null)\n\nCount the number of times a string contains a substring.\n\nExcludes overlaps.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| **`$substr`** | `string` |  |\n| **`$offset`** | `int` | Optionally provide a starting offset. |\n| **`$length`** | `int|null` | Optionally provide a maximum length. |\n| returns | `int` |  |\n\n#### StringUtil::characterRun($s, $chars, $begin = 0, $end = null)\n\nCount a number of matching characters at the beginning of a string.\n\nDetermines the length of the initial segment of a string which\ncontains only the characters listed in `$chars`.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| **`$chars`** | `string` | A list of characters. |\n| **`$begin`** | `int` | Optionally provide a starting offset. |\n| **`$end`** | `int|null` | Optionally provide an ending offset. |\n| returns | `int` |  |\n\n#### StringUtil::escapeCString($s)\n\nEscape a string C-style.\n\nEscapes a string by adding backslashes in front of certain\ncharacters and encoding non-printable characters with octal codes,\njust like in C string literals.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `string` |\n\n#### StringUtil::unescapeCString($s)\n\nUn-escape the contents of a C-style string literal.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `string` |\n\n#### StringUtil::escapePhpString($s)\n\nEscape a string PHP-style.\n\nEscapes a string by placing backslashes before special characters as\nrequired by PHP.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `string` |\n\n#### StringUtil::unescapeBackslashes($s)\n\nRemove all backslash (`\\`) escape characters from a string.\n\nNote that this does not interpret `\\n` as a newline, `\\t` as tab,\netc., but as the literal characters `n`, `t`, etc.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `string` |\n\n#### StringUtil::parseInt($s, $base = null)\n\nParse a string as an integer according to a certain base.\n\nIf `$base` is `null`, the base is deduced from the prefix of the\nstring (`0x` for hexadecimal, `0` for octal, and decimal otherwise).\nIgnores any invalid trailing characters.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| **`$base`** | `int|null` |\n| returns | `string` |\n\n#### StringUtil::parseReal($s)\n\nParse a floating-point value.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| returns | `string` |  |\n| throws | `RuntimeException` | Thrown if `$s` is not a valid float string. |\n\n#### StringUtil::encodeHex($s)\n\nConvert a binary string to a hexadecimal string.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `string` |\n\n#### StringUtil::decodeHex($s)\n\nParse a hexadecimal string into binary data.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `string` |\n\n#### StringUtil::encodeBase64($s)\n\nEncode a binary string in base 64.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `string` |\n\n#### StringUtil::decodeBase64($s)\n\nDecode a base 64 string to binary.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `string` |\n\n#### StringUtil::fromAscii($n)\n\nConvert an ASCII codepoint to the corresponding character.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$n`** | `int` |  |\n| returns | `string` | A single character. |\n\n#### StringUtil::chr($n)\n\nAlias for `fromASCII`.\n\nSee `\\Jitsu\\StringUtil::fromAscii()`.\n\n|   | Type |\n|---|------|\n| **`$n`** | `int` |\n| returns | `string` |\n\n#### StringUtil::toAscii($c)\n\nConvert a character to its ASCII codepoint.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$c`** | `string` | A single character. |\n| returns | `int` |  |\n\n#### StringUtil::ord($c)\n\nAlias for `toASCII`.\n\nSee `\\Jitsu\\StringUtil::toAscii()`.\n\n|   | Type |\n|---|------|\n| **`$c`** | `string` |\n| returns | `int` |\n\n#### StringUtil::byteCounts($s)\n\nTally the occurrences of the 256 possible byte values in a string.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| returns | `int[]` | Maps each byte value (0-255) to the number of its occurences in `$s`. |\n\n#### StringUtil::unique($s)\n\nList all of the unique byte values in a string.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `string` |\n\n#### StringUtil::unusedBytes($s)\n\nList all byte values which do not occur in a string.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `string` |\n\n#### StringUtil::encodeHtml($s, $noquote = false)\n\nEscape special HTML characters with character entities.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| **`$noquote`** | `bool` | Whether double quotes (`\"`) will be left un-escaped. |\n| returns | `string` |  |\n\n#### StringUtil::escapeHtml($s, $noquote = false)\n\nAlias of `encodeHtml`.\n\nSee `\\Jitsu\\StringUtil::encodeHtml()`.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| **`$noquote`** | `bool` |\n| returns | `string` |\n\n#### StringUtil::unencodeHtml($s)\n\nInverse of `encodeHtml`.\n\nThe term \"unencode\" is used here as opposed to \"decode\" to emphasize\nthe fact that this function is not suitable for decoding arbitrary\nHTML text, but rather HTML encoded by `encodeHtml` using only a\nminimal set of named character entity codes. This function does not\nrecognize named entities except for those encoded by `encodeHtml`\nas well as `\u0026apos;`. It will decode numeric entities except for\nthose corresponding to non-printable characters, which it will leave\nencoded.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `string` |\n\n#### StringUtil::encodeHtmlDict($noquote = false)\n\nGenerate a minimal replacement dictionary for escaping special HTML\ncharacters using their HTML5 character entities.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$noquote`** | `bool` | Whether the double quote (`\"`) will be omitted. |\n| returns | `string[]` |  |\n\n#### StringUtil::encodeHtmlEntities($s)\n\nReplace characters in a string with their equivalent HTML5 named\ncharacter entities wherever possible.\n\nThis ability is not particularly useful, and `encodeHTML` should\nbe preferred instead for efficiency.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `string` |\n\n#### StringUtil::encodeHtmlEntitiesDict()\n\nGenerate the (fairly large) replacement dictionary for encoding\ncharacters to named HTML5 character entities wherever possible.\n\n|   | Type | Description |\n|---|------|-------------|\n| returns | `string[]` | Maps characters to character entities. |\n\n#### StringUtil::stripTags($s)\n\nStrip HTML and PHP tags from a string.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `string` |\n\n#### StringUtil::parseRawQueryString($s)\n\nURL-decode and parse a query string.\n\nNote that this assumes the PHP convention of parameter names ending\nwith `[]` to denote arrays of values; in cases where parameters\nshare the same name, only the last one is included.\n\nAlso note that this automatically URL-decodes the query string; it\nis incorrect to use this on a string which is not URL-encoded.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| returns | `string[]` | Maps parameter names to string values. |\n\n#### StringUtil::encodeStandardQueryString($data, $sep = '\u0026')\n\nFormat and URL-encode data as a query string.\n\nThis adheres to the standard which does not encode spaces as `+`.\n\nFor compatibility reasons, `encodeQueryString` should be preferred. See `\\Jitsu\\StringUtil::encodeQueryString()`.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$data`** | `array|object` | The data to encode in the query string. |\n| **`$sep`** | `string` | Optionally provide a separator other than `\u0026`, such as `;`. |\n| returns | `string` |  |\n\n#### StringUtil::encodeQueryString($data, $sep = '\u0026')\n\nFormat and URL-encode data as a query string, encoding spaces as\n`+`.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$data`** | `array|object` | The data to encode in the query string. |\n| **`$sep`** | `string` | Optionally provide a separator other than `\u0026`, such as `;`. |\n| returns | `string` |  |\n\n#### StringUtil::encodeStandardUrl($s)\n\nURL-encode a string.\n\nThis adheres to the standard which does not encode spaces as `+`.\n\nFor compatibility reasons, `encodeUrl` should be preferred. See `\\Jitsu\\StringUtil::encodeUrl()`.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `string` |\n\n#### StringUtil::decodeStandardUrl($s)\n\nDecode a URL-encoded string.\n\nThis adheres to the standard which does not encode spaces as `+`.\n\nFor compatibility reasons, `decodeUrl` should be preferred. See `\\Jitsu\\StringUtil::decodeUrl()`.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `string` |\n\n#### StringUtil::encodeUrl($s)\n\nURL-encode a string, using `+` to encode spaces.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `string` |\n\n#### StringUtil::decodeUrl($s)\n\nDecode a URL-encoded string, treating `+` as space.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `string` |\n\n#### StringUtil::parseCsv($s, $delim = ',', $quote = '\"', $escape = '\\\\\\\\')\n\nParse a CSV line into an array.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s`** | `string` |  |\n| **`$delim`** | `string` | Optional delimiter character. Default is `,`. |\n| **`$quote`** | `string` | Optional enclosure (quote) character. Default is `\"`. |\n| **`$escape`** | `string` | Optional escape character. Default is `\\\\`. |\n| returns | `string[]` |  |\n\n#### StringUtil::md5($s)\n\nCompute the MD5 hash of a string as a 16-byte binary string.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `string` |\n\n#### StringUtil::md5Hex($s)\n\nCompute the MD5 hash of a string as a hex string.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `string` |\n\n#### StringUtil::sha1($s)\n\nCompute the SHA1 hash of a string as a 20-byte binary string.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `string` |\n\n#### StringUtil::sha1Hex($s)\n\nCompute the SHA1 hash of a string as a hex string.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `string` |\n\n#### StringUtil::rot13($s)\n\nApply rot13 encryption to a string.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `string` |\n\n#### StringUtil::shuffle($s)\n\nRandomly shuffle the characters of a string.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `string` |\n\n#### StringUtil::formatMoney($amount)\n\nFormat a number as a currency value using the current locale.\n\nNote that this requires setting the locale using\n`setlocale(LC_ALL, $locale)` or `setlocale(LC_MONETARY, $locale)`\nfor some locale that is installed on the system.\n\n|   | Type |\n|---|------|\n| **`$amount`** | `int|float` |\n| returns | `string` |\n\n#### StringUtil::formatNumber($number, $decimals = 0, $decimal\\_point = '.', $thousands\\_sep = ',')\n\nFormat a number with commas and a decimal point.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$number`** | `int|float` |  |\n| **`$decimals`** | `int` | Optional number of decimal places. Default is 0. |\n| **`$decimal_point`** | `string` | Optional decimal point character. Default is `.`. |\n| **`$thousands_sep`** | `string` | Optional thousands separator. Default is `,`. |\n| returns | `string` |  |\n\n#### StringUtil::levenshtein($s1, $s2, $ins = null, $repl = null, $del = null)\n\nCompute the Levenshtein distance between two strings.\n\nThe Levenshtein distance is the minimum number of character\nreplacements, insertions, and deletions necessary to transform `$s1`\ninto `$s2`.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$s1`** | `string` |  |\n| **`$s2`** | `string` |  |\n| **`$ins`** | `int` | Optional cost per insertion. |\n| **`$repl`** | `int` | Optional cost per replacement. |\n| **`$del`** | `int` | Optional cost per deletion. |\n| returns | `int` |  |\n\n#### StringUtil::splitCamelCase($s)\n\nSplit a string in camel case into its components.\n\nRuns of consecutive capital letters are treated as acronyms and are\ngrouped accordingly.\n\nFor example, the string \"XMLHttpRequest\" would be split into \"XML\",\n\"Http\", \"Request\".\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `string` |\n\n#### StringUtil::pluralize($s)\n\nConvert an English word to its plural or \"-s\" form.\n\nOne could use this to form the plural form of a noun or the third\nperson singular form of a verb.\n\nThis uses a naive algorithm which will not work for irregular forms\nand for certain other cases. However, it knows enough to convert\ncommon endings like \"-y\" to \"-ies\", \"-s\" to \"-ses\", and so on.\n\n|   | Type |\n|---|------|\n| **`$s`** | `string` |\n| returns | `string` |\n\n#### StringUtil::capture($callback)\n\nCapture all output printed in a callback.\n\nUses PHP output buffering to capture all of the output `echo`ed in\na callback. If the callback throws an exception, the output will be\nignored, and the exception will be re-thrown.\n\n|   | Type | Description |\n|---|------|-------------|\n| **`$callback`** | `callable` |  |\n| returns | `string` |  |\n| throws | `\\Exception` | Whatever `$callback` throws. |\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbdusell%2Fjitsu-string","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbdusell%2Fjitsu-string","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbdusell%2Fjitsu-string/lists"}