diff --git a/index.html b/index.html index 1119d31..19d1ecc 100644 --- a/index.html +++ b/index.html @@ -5,7 +5,7 @@ Stringy by danielstjules - + @@ -35,6 +35,7 @@ for older documentation.

  • OO and Chaining
  • Implemented Interfaces
  • PHP 5.6 Creation
  • +
  • StaticStringy
  • Class methods @@ -157,7 +158,7 @@ to work with!

    in your composer.json file:

    "require": {
    -    "danielstjules/stringy": "~2.0"
    +    "danielstjules/stringy": "~2.1"
     }

    Then, after running composer update or php composer.phar update, you can @@ -239,6 +240,20 @@ you can take advantage of an even simpler API as seen below:

    // Instead of: S::create('fòô bàř') s('fòô bàř')->collapseWhitespace()->swapCase(); +

    +StaticStringy

    + +

    All methods listed under "Instance methods" are available as part of a static +wrapper. For StaticStringy methods, the optional encoding is expected to be the +last argument. The return value is not cast, and may thus be of type Stringy, +integer, boolean, etc.

    + +
    use Stringy\StaticStringy as S;
    +
    +// Translates to Stringy::create('fòôbàř', 'UTF-8')->slice(0, 3);
    +// Returns a Stringy object with the string "fòô"
    +S::slice('fòôbàř', 0, 3, 'UTF-8');
    +

    Class methods

    @@ -923,4 +938,3 @@ Advanced substring methods
  • - diff --git a/params.json b/params.json index f4ebfa6..628380b 100644 --- a/params.json +++ b/params.json @@ -1 +1 @@ -{"name":"Stringy","tagline":"A PHP string manipulation library with multibyte support","body":"![Stringy](http://danielstjules.com/github/stringy-logo.png)\r\n\r\nA PHP string manipulation library with multibyte support. Compatible with PHP\r\n5.3+ and HHVM. Refer to the [1.x branch](https://github.com/danielstjules/Stringy/tree/1.x)\r\nfor older documentation.\r\n\r\n``` php\r\ns('string')->toTitleCase()->ensureRight('y') == 'Stringy'\r\n```\r\n\r\n[![Build Status](https://api.travis-ci.org/danielstjules/Stringy.svg?branch=master)](https://travis-ci.org/danielstjules/Stringy)\r\n\r\n* [Why?](#why)\r\n* [Installation](#installation)\r\n* [OO and Chaining](#oo-and-chaining)\r\n* [Implemented Interfaces](#implemented-interfaces)\r\n* [PHP 5.6 Creation](#php-56-creation)\r\n* [Class methods](#class-methods)\r\n * [create](#createmixed-str--encoding-)\r\n* [Instance methods](#instance-methods)\r\n * [append](#appendstring-string)\r\n * [at](#atint-index)\r\n * [between](#betweenstring-start-string-end--int-offset)\r\n * [camelize](#camelize)\r\n * [chars](#chars)\r\n * [collapseWhitespace](#collapsewhitespace)\r\n * [contains](#containsstring-needle--boolean-casesensitive--true-)\r\n * [containsAll](#containsallarray-needles--boolean-casesensitive--true-)\r\n * [containsAny](#containsanyarray-needles--boolean-casesensitive--true-)\r\n * [countSubstr](#countsubstrstring-substring--boolean-casesensitive--true-)\r\n * [dasherize](#dasherize)\r\n * [delimit](#delimitint-delimiter)\r\n * [endsWith](#endswithstring-substring--boolean-casesensitive--true-)\r\n * [ensureLeft](#ensureleftstring-substring)\r\n * [ensureRight](#ensurerightstring-substring)\r\n * [first](#firstint-n)\r\n * [getEncoding](#getencoding)\r\n * [hasLowerCase](#haslowercase)\r\n * [hasUpperCase](#hasuppercase)\r\n * [htmlDecode](#htmldecode)\r\n * [htmlEncode](#htmlencode)\r\n * [humanize](#humanize)\r\n * [indexOf](#indexofstring-needle--offset--0-)\r\n * [indexOfLast](#indexoflaststring-needle--offset--0-)\r\n * [insert](#insertint-index-string-substring)\r\n * [isAlpha](#isalpha)\r\n * [isAlphanumeric](#isalphanumeric)\r\n * [isBlank](#isblank)\r\n * [isHexadecimal](#ishexadecimal)\r\n * [isJson](#isjson)\r\n * [isLowerCase](#islowercase)\r\n * [isSerialized](#isserialized)\r\n * [isUpperCase](#isuppercase)\r\n * [last](#last)\r\n * [length](#length)\r\n * [lines](#lines)\r\n * [longestCommonPrefix](#longestcommonprefixstring-otherstr)\r\n * [longestCommonSuffix](#longestcommonsuffixstring-otherstr)\r\n * [longestCommonSubstring](#longestcommonsubstringstring-otherstr)\r\n * [lowerCaseFirst](#lowercasefirst)\r\n * [pad](#padint-length--string-padstr-----string-padtype--right-)\r\n * [padBoth](#padbothint-length--string-padstr----)\r\n * [padLeft](#padleftint-length--string-padstr----)\r\n * [padRight](#padrightint-length--string-padstr----)\r\n * [prepend](#prependstring-string)\r\n * [regexReplace](#regexreplacestring-pattern-string-replacement--string-options--msr)\r\n * [removeLeft](#removeleftstring-substring)\r\n * [removeRight](#removerightstring-substring)\r\n * [repeat](#repeatmultiplier)\r\n * [replace](#replacestring-search-string-replacement)\r\n * [reverse](#reverse)\r\n * [safeTruncate](#safetruncateint-length--string-substring---)\r\n * [shuffle](#shuffle)\r\n * [slugify](#slugify-string-replacement----)\r\n * [startsWith](#startswithstring-substring--boolean-casesensitive--true-)\r\n * [slice](#sliceint-start--int-end-)\r\n * [split](#splitstring-pattern--int-limit-)\r\n * [substr](#substrint-start--int-length-)\r\n * [surround](#surroundstring-substring)\r\n * [swapCase](#swapcase)\r\n * [tidy](#tidy)\r\n * [titleize](#titleize-array-ignore)\r\n * [toAscii](#toascii)\r\n * [toBoolean](#toboolean)\r\n * [toLowerCase](#tolowercase)\r\n * [toSpaces](#tospaces-tablength--4-)\r\n * [toTabs](#totabs-tablength--4-)\r\n * [toTitleCase](#totitlecase)\r\n * [toUpperCase](#touppercase)\r\n * [trim](#trim-string-chars)\r\n * [trimLeft](#trimleft-string-chars)\r\n * [trimRight](#trimright-string-chars)\r\n * [truncate](#truncateint-length--string-substring---)\r\n * [underscored](#underscored)\r\n * [upperCamelize](#uppercamelize)\r\n * [upperCaseFirst](#uppercasefirst)\r\n* [Extensions](#extensions)\r\n* [Tests](#tests)\r\n* [License](#license)\r\n\r\n## Why?\r\n\r\nIn part due to a lack of multibyte support (including UTF-8) across many of\r\nPHP's standard string functions. But also to offer an OO wrapper around the\r\n`mbstring` module's multibyte-compatible functions. Stringy handles some quirks,\r\nprovides additional functionality, and hopefully makes strings a little easier\r\nto work with!\r\n\r\n```php\r\n// Standard library\r\nstrtoupper('fòôbàř'); // 'FòôBàř'\r\nstrlen('fòôbàř'); // 10\r\n\r\n// mbstring\r\nmb_strtoupper('fòôbàř'); // 'FÒÔBÀŘ'\r\nmb_strlen('fòôbàř'); // '6'\r\n\r\n// Stringy\r\ns('fòôbàř')->toUpperCase(); // 'FÒÔBÀŘ'\r\ns('fòôbàř')->length(); // '6'\r\n```\r\n\r\n## Installation\r\n\r\nIf you're using Composer to manage dependencies, you can include the following\r\nin your composer.json file:\r\n\r\n```json\r\n\"require\": {\r\n \"danielstjules/stringy\": \"~2.0\"\r\n}\r\n```\r\n\r\nThen, after running `composer update` or `php composer.phar update`, you can\r\nload the class using Composer's autoloading:\r\n\r\n```php\r\nrequire 'vendor/autoload.php';\r\n```\r\n\r\nOtherwise, you can simply require the file directly:\r\n\r\n```php\r\nrequire_once 'path/to/Stringy/src/Stringy.php';\r\n```\r\n\r\nAnd in either case, I'd suggest using an alias.\r\n\r\n```php\r\nuse Stringy\\Stringy as S;\r\n```\r\n\r\nPlease note that Stringy relies on the `mbstring` PHP module for its underlying\r\nmultibyte support. This is a non-default, but very common module. For example,\r\nwith debian and ubuntu, it's included in libapache2-mod-php5, php5-cli, and\r\nphp5-fpm. For OSX users, it's a default for any version of PHP installed with\r\nhomebrew. If compiling PHP from scratch, it can be included with the\r\n`--enable-mbstring` flag.\r\n\r\n## OO and Chaining\r\n\r\nThe library offers OO method chaining, as seen below:\r\n\r\n```php\r\nuse Stringy\\Stringy as S;\r\necho S::create('fòô bàř')->collapseWhitespace()->swapCase(); // 'FÒÔ BÀŘ'\r\n```\r\n\r\n`Stringy\\Stringy` has a __toString() method, which returns the current string\r\nwhen the object is used in a string context, ie:\r\n`(string) S::create('foo') // 'foo'`\r\n\r\n## Implemented Interfaces\r\n\r\n`Stringy\\Stringy` implements the `IteratorAggregate` interface, meaning that\r\n`foreach` can be used with an instance of the class:\r\n\r\n``` php\r\n$stringy = S::create('fòôbàř');\r\nforeach ($stringy as $char) {\r\n echo $char;\r\n}\r\n// 'fòôbàř'\r\n```\r\n\r\nIt implements the `Countable` interface, enabling the use of `count()` to\r\nretrieve the number of characters in the string:\r\n\r\n``` php\r\n$stringy = S::create('fòô');\r\ncount($stringy); // 3\r\n```\r\n\r\nFurthermore, the `ArrayAccess` interface has been implemented. As a result,\r\n`isset()` can be used to check if a character at a specific index exists. And\r\nsince `Stringy\\Stringy` is immutable, any call to `offsetSet` or `offsetUnset`\r\nwill throw an exception. `offsetGet` has been implemented, however, and accepts\r\nboth positive and negative indexes. Invalid indexes result in an\r\n`OutOfBoundsException`.\r\n\r\n``` php\r\n$stringy = S::create('bàř');\r\necho $stringy[2]; // 'ř'\r\necho $stringy[-2]; // 'à'\r\nisset($stringy[-4]); // false\r\n\r\n$stringy[3]; // OutOfBoundsException\r\n$stringy[2] = 'a'; // Exception\r\n```\r\n\r\n## PHP 5.6 Creation\r\n\r\nAs of PHP 5.6, [`use function`](https://wiki.php.net/rfc/use_function) is\r\navailable for importing functions. Stringy exposes a namespaced function,\r\n`Stringy\\create`, which emits the same behaviour as `Stringy\\Stringy::create()`.\r\nIf running PHP 5.6, or another runtime that supports the `use function` syntax,\r\nyou can take advantage of an even simpler API as seen below:\r\n\r\n``` php\r\nuse function Stringy\\create as s;\r\n\r\n// Instead of: S::create('fòô bàř')\r\ns('fòô bàř')->collapseWhitespace()->swapCase();\r\n```\r\n\r\n## Class methods\r\n\r\n##### create(mixed $str [, $encoding ])\r\n\r\nCreates a Stringy object and assigns both str and encoding properties\r\nthe supplied values. $str is cast to a string prior to assignment, and if\r\n$encoding is not specified, it defaults to mb_internal_encoding(). It\r\nthen returns the initialized object. Throws an InvalidArgumentException\r\nif the first argument is an array or object without a __toString method.\r\n\r\n```php\r\n$stringy = S::create('fòôbàř', 'UTF-8'); // 'fòôbàř'\r\n```\r\n\r\n## Instance Methods\r\n\r\nStringy objects are immutable. All examples below make use of PHP 5.6\r\nfunction importing, and PHP 5.4 short array syntax. They also assume the\r\nencoding returned by mb_internal_encoding() is UTF-8. For further details,\r\nsee the documentation for the create method above, as well as the notes\r\non PHP 5.6 creation.\r\n\r\n##### append(string $string)\r\n\r\nReturns a new string with $string appended.\r\n\r\n```php\r\ns('fòô')->append('bàř'); // 'fòôbàř'\r\n```\r\n\r\n##### at(int $index)\r\n\r\nReturns the character at $index, with indexes starting at 0.\r\n\r\n```php\r\ns('fòôbàř')->at(3); // 'b'\r\n```\r\n\r\n##### between(string $start, string $end [, int $offset])\r\n\r\nReturns the substring between $start and $end, if found, or an empty\r\nstring. An optional offset may be supplied from which to begin the\r\nsearch for the start string.\r\n\r\n```php\r\ns('{foo} and {bar}')->between('{', '}'); // 'foo'\r\n```\r\n\r\n##### camelize()\r\n\r\nReturns a camelCase version of the string. Trims surrounding spaces,\r\ncapitalizes letters following digits, spaces, dashes and underscores,\r\nand removes spaces, dashes, as well as underscores.\r\n\r\n```php\r\ns('Camel-Case')->camelize(); // 'camelCase'\r\n```\r\n\r\n##### chars()\r\n\r\nReturns an array consisting of the characters in the string.\r\n\r\n```php\r\ns('fòôbàř')->chars(); // ['f', 'ò', 'ô', 'b', 'à', 'ř']\r\n```\r\n\r\n##### collapseWhitespace()\r\n\r\nTrims the string and replaces consecutive whitespace characters with a\r\nsingle space. This includes tabs and newline characters, as well as\r\nmultibyte whitespace such as the thin space and ideographic space.\r\n\r\n```php\r\ns(' Ο συγγραφέας ')->collapseWhitespace(); // 'Ο συγγραφέας'\r\n```\r\n\r\n##### contains(string $needle [, boolean $caseSensitive = true ])\r\n\r\nReturns true if the string contains $needle, false otherwise. By default,\r\nthe comparison is case-sensitive, but can be made insensitive\r\nby setting $caseSensitive to false.\r\n\r\n```php\r\ns('Ο συγγραφέας είπε')->contains('συγγραφέας'); // true\r\n```\r\n\r\n##### containsAll(array $needles [, boolean $caseSensitive = true ])\r\n\r\nReturns true if the string contains all $needles, false otherwise. By\r\ndefault the comparison is case-sensitive, but can be made insensitive by\r\nsetting $caseSensitive to false.\r\n\r\n```php\r\ns('foo & bar')->containsAll(['foo', 'bar']); // true\r\n```\r\n\r\n##### containsAny(array $needles [, boolean $caseSensitive = true ])\r\n\r\nReturns true if the string contains any $needles, false otherwise. By\r\ndefault the comparison is case-sensitive, but can be made insensitive by\r\nsetting $caseSensitive to false.\r\n\r\n```php\r\ns('str contains foo')->containsAny(['foo', 'bar']); // true\r\n```\r\n\r\n##### countSubstr(string $substring [, boolean $caseSensitive = true ])\r\n\r\nReturns the number of occurrences of $substring in the given string.\r\nBy default, the comparison is case-sensitive, but can be made insensitive\r\nby setting $caseSensitive to false.\r\n\r\n```php\r\ns('Ο συγγραφέας είπε')->countSubstr('α'); // 2\r\n```\r\n\r\n##### dasherize()\r\n\r\nReturns a lowercase and trimmed string separated by dashes. Dashes are\r\ninserted before uppercase characters (with the exception of the first\r\ncharacter of the string), and in place of spaces as well as underscores.\r\n\r\n```php\r\ns('fooBar')->dasherize(); // 'foo-bar'\r\n```\r\n\r\n##### delimit(int $delimiter)\r\n\r\nReturns a lowercase and trimmed string separated by the given delimiter.\r\nDelimiters are inserted before uppercase characters (with the exception\r\nof the first character of the string), and in place of spaces, dashes,\r\nand underscores. Alpha delimiters are not converted to lowercase.\r\n\r\n```php\r\ns('fooBar')->delimit('::'); // 'foo::bar'\r\n```\r\n\r\n##### endsWith(string $substring [, boolean $caseSensitive = true ])\r\n\r\nReturns true if the string ends with $substring, false otherwise. By\r\ndefault, the comparison is case-sensitive, but can be made insensitive by\r\nsetting $caseSensitive to false.\r\n\r\n```php\r\ns('fòôbàř')->endsWith('bàř', true); // true\r\n```\r\n\r\n##### ensureLeft(string $substring)\r\n\r\nEnsures that the string begins with $substring. If it doesn't, it's prepended.\r\n\r\n```php\r\ns('foobar')->ensureLeft('http://'); // 'http://foobar'\r\n```\r\n\r\n##### ensureRight(string $substring)\r\n\r\nEnsures that the string begins with $substring. If it doesn't, it's appended.\r\n\r\n```php\r\ns('foobar')->ensureRight('.com'); // 'foobar.com'\r\n```\r\n\r\n##### first(int $n)\r\n\r\nReturns the first $n characters of the string.\r\n\r\n```php\r\ns('fòôbàř')->first(3); // 'fòô'\r\n```\r\n\r\n##### getEncoding()\r\n\r\nReturns the encoding used by the Stringy object.\r\n\r\n```php\r\ns('fòôbàř', 'UTF-8')->getEncoding(); // 'UTF-8'\r\n```\r\n\r\n##### hasLowerCase()\r\n\r\nReturns true if the string contains a lower case char, false otherwise.\r\n\r\n```php\r\ns('fòôbàř')->hasLowerCase(); // true\r\n```\r\n\r\n##### hasUpperCase()\r\n\r\nReturns true if the string contains an upper case char, false otherwise.\r\n\r\n```php\r\ns('fòôbàř')->hasUpperCase(); // false\r\n```\r\n\r\n##### htmlDecode()\r\n\r\nConvert all HTML entities to their applicable characters. An alias of\r\nhtml_entity_decode. For a list of flags, refer to\r\nhttp://php.net/manual/en/function.html-entity-decode.php\r\n\r\n```php\r\ns('&')->htmlDecode(); // '&'\r\n```\r\n\r\n##### htmlEncode()\r\n\r\nConvert all applicable characters to HTML entities. An alias of\r\nhtmlentities. Refer to http://php.net/manual/en/function.htmlentities.php\r\nfor a list of flags.\r\n\r\n```php\r\ns('&')->htmlEncode(); // '&'\r\n```\r\n\r\n##### humanize()\r\n\r\nCapitalizes the first word of the string, replaces underscores with\r\nspaces, and strips '_id'.\r\n\r\n```php\r\ns('author_id')->humanize(); // 'Author'\r\n```\r\n\r\n##### indexOf(string $needle [, $offset = 0 ]);\r\n\r\nReturns the index of the first occurrence of $needle in the string,\r\nand false if not found. Accepts an optional offset from which to begin\r\nthe search. A negative index searches from the end\r\n\r\n```php\r\ns('string')->indexOf('ing'); // 3\r\n```\r\n\r\n##### indexOfLast(string $needle [, $offset = 0 ]);\r\n\r\nReturns the index of the last occurrence of $needle in the string,\r\nand false if not found. Accepts an optional offset from which to begin\r\nthe search. Offsets may be negative to count from the last character\r\nin the string.\r\n\r\n```php\r\ns('foobarfoo')->indexOfLast('foo'); // 10\r\n```\r\n\r\n##### insert(int $index, string $substring)\r\n\r\nInserts $substring into the string at the $index provided.\r\n\r\n```php\r\ns('fòôbř')->insert('à', 4); // 'fòôbàř'\r\n```\r\n\r\n##### isAlpha()\r\n\r\nReturns true if the string contains only alphabetic chars, false otherwise.\r\n\r\n```php\r\ns('丹尼爾')->isAlpha(); // true\r\n```\r\n\r\n##### isAlphanumeric()\r\n\r\nReturns true if the string contains only alphabetic and numeric chars, false\r\notherwise.\r\n\r\n```php\r\ns('دانيال1')->isAlphanumeric(); // true\r\n```\r\n\r\n##### isBlank()\r\n\r\nReturns true if the string contains only whitespace chars, false otherwise.\r\n\r\n```php\r\ns(\"\\n\\t \\v\\f\")->isBlank(); // true\r\n```\r\n\r\n##### isHexadecimal()\r\n\r\nReturns true if the string contains only hexadecimal chars, false otherwise.\r\n\r\n```php\r\ns('A102F')->isHexadecimal(); // true\r\n```\r\n\r\n##### isJson()\r\n\r\nReturns true if the string is JSON, false otherwise.\r\n\r\n```php\r\ns('{\"foo\":\"bar\"}')->isJson(); // true\r\n```\r\n\r\n##### isLowerCase()\r\n\r\nReturns true if the string contains only lower case chars, false otherwise.\r\n\r\n```php\r\ns('fòôbàř')->isLowerCase(); // true\r\n```\r\n\r\n##### isSerialized()\r\n\r\nReturns true if the string is serialized, false otherwise.\r\n\r\n```php\r\ns('a:1:{s:3:\"foo\";s:3:\"bar\";}')->isSerialized(); // true\r\n```\r\n\r\n##### isUpperCase()\r\n\r\nReturns true if the string contains only upper case chars, false otherwise.\r\n\r\n```php\r\ns('FÒÔBÀŘ')->isUpperCase(); // true\r\n```\r\n\r\n##### last(int $n)\r\n\r\nReturns the last $n characters of the string.\r\n\r\n```php\r\ns('fòôbàř')->last(3); // 'bàř'\r\n```\r\n\r\n##### length()\r\n\r\nReturns the length of the string. An alias for PHP's mb_strlen() function.\r\n\r\n```php\r\ns('fòôbàř')->length(); // 6\r\n```\r\n\r\n##### lines()\r\n\r\nSplits on newlines and carriage returns, returning an array of Stringy\r\nobjects corresponding to the lines in the string.\r\n\r\n```php\r\ns(\"fòô\\r\\nbàř\\n\")->lines(); // ['fòô', 'bàř', '']\r\n```\r\n\r\n##### longestCommonPrefix(string $otherStr)\r\n\r\nReturns the longest common prefix between the string and $otherStr.\r\n\r\n```php\r\ns('foobar')->longestCommonPrefix('foobaz'); // 'fooba'\r\n```\r\n\r\n##### longestCommonSuffix(string $otherStr)\r\n\r\nReturns the longest common suffix between the string and $otherStr.\r\n\r\n```php\r\ns('fòôbàř')->longestCommonSuffix('fòrbàř'); // 'bàř'\r\n```\r\n\r\n##### longestCommonSubstring(string $otherStr)\r\n\r\nReturns the longest common substring between the string and $otherStr. In the\r\ncase of ties, it returns that which occurs first.\r\n\r\n```php\r\ns('foobar')->longestCommonSubstring('boofar'); // 'oo'\r\n```\r\n\r\n##### lowerCaseFirst()\r\n\r\nConverts the first character of the supplied string to lower case.\r\n\r\n```php\r\ns('Σ foo')->lowerCaseFirst(); // 'σ foo'\r\n```\r\n\r\n##### pad(int $length [, string $padStr = ' ' [, string $padType = 'right' ]])\r\n\r\nPads the string to a given length with $padStr. If length is less than\r\nor equal to the length of the string, no padding takes places. The default\r\nstring used for padding is a space, and the default type (one of 'left',\r\n'right', 'both') is 'right'. Throws an InvalidArgumentException if\r\n$padType isn't one of those 3 values.\r\n\r\n```php\r\ns('fòôbàř')->pad(9, '-/', 'left'); // '-/-fòôbàř'\r\n```\r\n\r\n##### padBoth(int $length [, string $padStr = ' ' ])\r\n\r\nReturns a new string of a given length such that both sides of the string\r\nstring are padded. Alias for pad() with a $padType of 'both'.\r\n\r\n```php\r\ns('foo bar')->padBoth(9, ' '); // ' foo bar '\r\n```\r\n\r\n##### padLeft(int $length [, string $padStr = ' ' ])\r\n\r\nReturns a new string of a given length such that the beginning of the\r\nstring is padded. Alias for pad() with a $padType of 'left'.\r\n\r\n```php\r\ns('foo bar')->padLeft(9, ' '); // ' foo bar'\r\n```\r\n\r\n##### padRight(int $length [, string $padStr = ' ' ])\r\n\r\nReturns a new string of a given length such that the end of the string is\r\npadded. Alias for pad() with a $padType of 'right'.\r\n\r\n```php\r\ns('foo bar')->padRight(10, '_*'); // 'foo bar_*_'\r\n```\r\n\r\n##### prepend(string $string)\r\n\r\nReturns a new string starting with $string.\r\n\r\n```php\r\ns('bàř')->prepend('fòô'); // 'fòôbàř'\r\n```\r\n\r\n##### regexReplace(string $pattern, string $replacement [, string $options = 'msr'])\r\n\r\nReplaces all occurrences of $pattern in $str by $replacement. An alias\r\nfor mb_ereg_replace(). Note that the 'i' option with multibyte patterns\r\nin mb_ereg_replace() requires PHP 5.6+ for correct results. This is due\r\nto a lack of support in the bundled version of Oniguruma in PHP < 5.6,\r\nand current versions of HHVM (3.8 and below).\r\n\r\n```php\r\ns('fòô ')->regexReplace('f[òô]+\\s', 'bàř', 'msr'); // 'bàř'\r\n```\r\n\r\n##### removeLeft(string $substring)\r\n\r\nReturns a new string with the prefix $substring removed, if present.\r\n\r\n```php\r\ns('fòôbàř')->removeLeft('fòô'); // 'bàř'\r\n```\r\n\r\n##### removeRight(string $substring)\r\n\r\nReturns a new string with the suffix $substring removed, if present.\r\n\r\n```php\r\ns('fòôbàř')->removeRight('bàř'); // 'fòô'\r\n```\r\n\r\n##### repeat(int $multiplier)\r\n\r\nReturns a repeated string given a multiplier. An alias for str_repeat.\r\n\r\n```php\r\ns('α')->repeat(3); // 'ααα'\r\n```\r\n\r\n##### replace(string $search, string $replacement)\r\n\r\nReplaces all occurrences of $search in $str by $replacement.\r\n\r\n```php\r\ns('fòô bàř fòô bàř')->replace('fòô ', ''); // 'bàř bàř'\r\n```\r\n\r\n##### reverse()\r\n\r\nReturns a reversed string. A multibyte version of strrev().\r\n\r\n```php\r\ns('fòôbàř')->reverse(); // 'řàbôòf'\r\n```\r\n\r\n##### safeTruncate(int $length [, string $substring = '' ])\r\n\r\nTruncates the string to a given length, while ensuring that it does not\r\nsplit words. If $substring is provided, and truncating occurs, the\r\nstring is further truncated so that the substring may be appended without\r\nexceeding the desired length.\r\n\r\n```php\r\ns('What are your plans today?')->safeTruncate(22, '...');\r\n// 'What are your plans...'\r\n```\r\n\r\n##### shuffle()\r\n\r\nA multibyte str_shuffle() function. It returns a string with its characters in\r\nrandom order.\r\n\r\n```php\r\ns('fòôbàř')->shuffle(); // 'àôřbòf'\r\n```\r\n\r\n##### slugify([, string $replacement = '-' ])\r\n\r\nConverts the string into an URL slug. This includes replacing non-ASCII\r\ncharacters with their closest ASCII equivalents, removing remaining\r\nnon-ASCII and non-alphanumeric characters, and replacing whitespace with\r\n$replacement. The replacement defaults to a single dash, and the string\r\nis also converted to lowercase.\r\n\r\n```php\r\ns('Using strings like fòô bàř')->slugify(); // 'using-strings-like-foo-bar'\r\n```\r\n\r\n##### startsWith(string $substring [, boolean $caseSensitive = true ])\r\n\r\nReturns true if the string begins with $substring, false otherwise.\r\nBy default, the comparison is case-sensitive, but can be made insensitive\r\nby setting $caseSensitive to false.\r\n\r\n```php\r\ns('FÒÔbàřbaz')->startsWith('fòôbàř', false); // true\r\n```\r\n\r\n##### slice(int $start [, int $end ])\r\n\r\nReturns the substring beginning at $start, and up to, but not including\r\nthe index specified by $end. If $end is omitted, the function extracts\r\nthe remaining string. If $end is negative, it is computed from the end\r\nof the string.\r\n\r\n```php\r\ns('fòôbàř')->slice(3, -1); // 'bà'\r\n```\r\n\r\n##### split(string $pattern [, int $limit ])\r\n\r\nSplits the string with the provided regular expression, returning an\r\narray of Stringy objects. An optional integer $limit will truncate the\r\nresults.\r\n\r\n```php\r\ns('foo,bar,baz')->split(',', 2); // ['foo', 'bar']\r\n```\r\n\r\n##### substr(int $start [, int $length ])\r\n\r\nReturns the substring beginning at $start with the specified $length.\r\nIt differs from the mb_substr() function in that providing a $length of\r\nnull will return the rest of the string, rather than an empty string.\r\n\r\n```php\r\ns('fòôbàř')->substr(2, 3); // 'ôbà'\r\n```\r\n\r\n##### surround(string $substring)\r\n\r\nSurrounds a string with the given substring.\r\n\r\n```php\r\ns(' ͜ ')->surround('ʘ'); // 'ʘ ͜ ʘ'\r\n```\r\n\r\n##### swapCase()\r\n\r\nReturns a case swapped version of the string.\r\n\r\n```php\r\ns('Ντανιλ')->swapCase(); // 'νΤΑΝΙΛ'\r\n```\r\n\r\n##### tidy()\r\n\r\nReturns a string with smart quotes, ellipsis characters, and dashes from\r\nWindows-1252 (commonly used in Word documents) replaced by their ASCII equivalents.\r\n\r\n```php\r\ns('“I see…”')->tidy(); // '\"I see...\"'\r\n```\r\n\r\n##### titleize([, array $ignore])\r\n\r\nReturns a trimmed string with the first letter of each word capitalized.\r\nAlso accepts an array, $ignore, allowing you to list words not to be\r\ncapitalized.\r\n\r\n```php\r\n$ignore = ['at', 'by', 'for', 'in', 'of', 'on', 'out', 'to', 'the'];\r\ns('i like to watch television')->titleize($ignore);\r\n// 'I Like to Watch Television'\r\n```\r\n\r\n##### toAscii()\r\n\r\nReturns an ASCII version of the string. A set of non-ASCII characters are\r\nreplaced with their closest ASCII counterparts, and the rest are removed\r\nunless instructed otherwise.\r\n\r\n```php\r\ns('fòôbàř')->toAscii(); // 'foobar'\r\n```\r\n\r\n##### toBoolean()\r\n\r\nReturns a boolean representation of the given logical string value.\r\nFor example, 'true', '1', 'on' and 'yes' will return true. 'false', '0',\r\n'off', and 'no' will return false. In all instances, case is ignored.\r\nFor other numeric strings, their sign will determine the return value.\r\nIn addition, blank strings consisting of only whitespace will return\r\nfalse. For all other strings, the return value is a result of a\r\nboolean cast.\r\n\r\n```php\r\ns('OFF')->toBoolean(); // false\r\n```\r\n\r\n##### toLowerCase()\r\n\r\nConverts all characters in the string to lowercase. An alias for PHP's\r\nmb_strtolower().\r\n\r\n```php\r\ns('FÒÔBÀŘ')->toLowerCase(); // 'fòôbàř'\r\n```\r\n\r\n##### toSpaces([, tabLength = 4 ])\r\n\r\nConverts each tab in the string to some number of spaces, as defined by\r\n$tabLength. By default, each tab is converted to 4 consecutive spaces.\r\n\r\n```php\r\ns(' String speech = \"Hi\"')->toSpaces(); // ' String speech = \"Hi\"'\r\n```\r\n\r\n##### toTabs([, tabLength = 4 ])\r\n\r\nConverts each occurrence of some consecutive number of spaces, as defined\r\nby $tabLength, to a tab. By default, each 4 consecutive spaces are\r\nconverted to a tab.\r\n\r\n```php\r\ns(' fòô bàř')->toTabs();\r\n// ' fòô bàř'\r\n```\r\n\r\n##### toTitleCase()\r\n\r\nConverts the first character of each word in the string to uppercase.\r\n\r\n```php\r\ns('fòô bàř')->toTitleCase(); // 'Fòô Bàř'\r\n```\r\n\r\n##### toUpperCase()\r\n\r\nConverts all characters in the string to uppercase. An alias for PHP's\r\nmb_strtoupper().\r\n\r\n```php\r\ns('fòôbàř')->toUpperCase(); // 'FÒÔBÀŘ'\r\n```\r\n\r\n##### trim([, string $chars])\r\n\r\nReturns a string with whitespace removed from the start and end of the\r\nstring. Supports the removal of unicode whitespace. Accepts an optional\r\nstring of characters to strip instead of the defaults.\r\n\r\n```php\r\ns(' fòôbàř ')->trim(); // 'fòôbàř'\r\n```\r\n\r\n##### trimLeft([, string $chars])\r\n\r\nReturns a string with whitespace removed from the start of the string.\r\nSupports the removal of unicode whitespace. Accepts an optional\r\nstring of characters to strip instead of the defaults.\r\n\r\n```php\r\ns(' fòôbàř ')->trimLeft(); // 'fòôbàř '\r\n```\r\n\r\n##### trimRight([, string $chars])\r\n\r\nReturns a string with whitespace removed from the end of the string.\r\nSupports the removal of unicode whitespace. Accepts an optional\r\nstring of characters to strip instead of the defaults.\r\n\r\n```php\r\ns(' fòôbàř ')->trimRight(); // ' fòôbàř'\r\n```\r\n\r\n##### truncate(int $length [, string $substring = '' ])\r\n\r\nTruncates the string to a given length. If $substring is provided, and\r\ntruncating occurs, the string is further truncated so that the substring\r\nmay be appended without exceeding the desired length.\r\n\r\n```php\r\ns('What are your plans today?')->truncate(19, '...'); // 'What are your pl...'\r\n```\r\n\r\n##### underscored()\r\n\r\nReturns a lowercase and trimmed string separated by underscores.\r\nUnderscores are inserted before uppercase characters (with the exception\r\nof the first character of the string), and in place of spaces as well as dashes.\r\n\r\n```php\r\ns('TestUCase')->underscored(); // 'test_u_case'\r\n```\r\n\r\n##### upperCamelize()\r\n\r\nReturns an UpperCamelCase version of the supplied string. It trims\r\nsurrounding spaces, capitalizes letters following digits, spaces, dashes\r\nand underscores, and removes spaces, dashes, underscores.\r\n\r\n```php\r\ns('Upper Camel-Case')->upperCamelize(); // 'UpperCamelCase'\r\n```\r\n\r\n##### upperCaseFirst()\r\n\r\nConverts the first character of the supplied string to upper case.\r\n\r\n```php\r\ns('σ foo')->upperCaseFirst(); // 'Σ foo'\r\n```\r\n\r\n## Extensions\r\n\r\nThe following is a list of libraries that extend Stringy:\r\n\r\n * [SliceableStringy](https://github.com/danielstjules/SliceableStringy):\r\nPython-like string slices in PHP\r\n * [SubStringy](https://github.com/TCB13/SubStringy):\r\nAdvanced substring methods\r\n\r\n## Tests\r\n\r\nFrom the project directory, tests can be ran using `phpunit`\r\n\r\n## License\r\n\r\nReleased under the MIT License - see `LICENSE.txt` for details.\r\n","google":"","note":"Don't delete this file! It's used internally to help with page regeneration."} \ No newline at end of file +{"name":"Stringy","tagline":"A PHP string manipulation library with multibyte support","body":"![Stringy](http://danielstjules.com/github/stringy-logo.png)\r\n\r\nA PHP string manipulation library with multibyte support. Compatible with PHP\r\n5.3+ and HHVM. Refer to the [1.x branch](https://github.com/danielstjules/Stringy/tree/1.x)\r\nfor older documentation.\r\n\r\n``` php\r\ns('string')->toTitleCase()->ensureRight('y') == 'Stringy'\r\n```\r\n\r\n[![Build Status](https://api.travis-ci.org/danielstjules/Stringy.svg?branch=master)](https://travis-ci.org/danielstjules/Stringy)\r\n\r\n* [Why?](#why)\r\n* [Installation](#installation)\r\n* [OO and Chaining](#oo-and-chaining)\r\n* [Implemented Interfaces](#implemented-interfaces)\r\n* [PHP 5.6 Creation](#php-56-creation)\r\n* [StaticStringy](#staticstringy)\r\n* [Class methods](#class-methods)\r\n * [create](#createmixed-str--encoding-)\r\n* [Instance methods](#instance-methods)\r\n * [append](#appendstring-string)\r\n * [at](#atint-index)\r\n * [between](#betweenstring-start-string-end--int-offset)\r\n * [camelize](#camelize)\r\n * [chars](#chars)\r\n * [collapseWhitespace](#collapsewhitespace)\r\n * [contains](#containsstring-needle--boolean-casesensitive--true-)\r\n * [containsAll](#containsallarray-needles--boolean-casesensitive--true-)\r\n * [containsAny](#containsanyarray-needles--boolean-casesensitive--true-)\r\n * [countSubstr](#countsubstrstring-substring--boolean-casesensitive--true-)\r\n * [dasherize](#dasherize)\r\n * [delimit](#delimitint-delimiter)\r\n * [endsWith](#endswithstring-substring--boolean-casesensitive--true-)\r\n * [ensureLeft](#ensureleftstring-substring)\r\n * [ensureRight](#ensurerightstring-substring)\r\n * [first](#firstint-n)\r\n * [getEncoding](#getencoding)\r\n * [hasLowerCase](#haslowercase)\r\n * [hasUpperCase](#hasuppercase)\r\n * [htmlDecode](#htmldecode)\r\n * [htmlEncode](#htmlencode)\r\n * [humanize](#humanize)\r\n * [indexOf](#indexofstring-needle--offset--0-)\r\n * [indexOfLast](#indexoflaststring-needle--offset--0-)\r\n * [insert](#insertint-index-string-substring)\r\n * [isAlpha](#isalpha)\r\n * [isAlphanumeric](#isalphanumeric)\r\n * [isBlank](#isblank)\r\n * [isHexadecimal](#ishexadecimal)\r\n * [isJson](#isjson)\r\n * [isLowerCase](#islowercase)\r\n * [isSerialized](#isserialized)\r\n * [isUpperCase](#isuppercase)\r\n * [last](#last)\r\n * [length](#length)\r\n * [lines](#lines)\r\n * [longestCommonPrefix](#longestcommonprefixstring-otherstr)\r\n * [longestCommonSuffix](#longestcommonsuffixstring-otherstr)\r\n * [longestCommonSubstring](#longestcommonsubstringstring-otherstr)\r\n * [lowerCaseFirst](#lowercasefirst)\r\n * [pad](#padint-length--string-padstr-----string-padtype--right-)\r\n * [padBoth](#padbothint-length--string-padstr----)\r\n * [padLeft](#padleftint-length--string-padstr----)\r\n * [padRight](#padrightint-length--string-padstr----)\r\n * [prepend](#prependstring-string)\r\n * [regexReplace](#regexreplacestring-pattern-string-replacement--string-options--msr)\r\n * [removeLeft](#removeleftstring-substring)\r\n * [removeRight](#removerightstring-substring)\r\n * [repeat](#repeatmultiplier)\r\n * [replace](#replacestring-search-string-replacement)\r\n * [reverse](#reverse)\r\n * [safeTruncate](#safetruncateint-length--string-substring---)\r\n * [shuffle](#shuffle)\r\n * [slugify](#slugify-string-replacement----)\r\n * [startsWith](#startswithstring-substring--boolean-casesensitive--true-)\r\n * [slice](#sliceint-start--int-end-)\r\n * [split](#splitstring-pattern--int-limit-)\r\n * [substr](#substrint-start--int-length-)\r\n * [surround](#surroundstring-substring)\r\n * [swapCase](#swapcase)\r\n * [tidy](#tidy)\r\n * [titleize](#titleize-array-ignore)\r\n * [toAscii](#toascii)\r\n * [toBoolean](#toboolean)\r\n * [toLowerCase](#tolowercase)\r\n * [toSpaces](#tospaces-tablength--4-)\r\n * [toTabs](#totabs-tablength--4-)\r\n * [toTitleCase](#totitlecase)\r\n * [toUpperCase](#touppercase)\r\n * [trim](#trim-string-chars)\r\n * [trimLeft](#trimleft-string-chars)\r\n * [trimRight](#trimright-string-chars)\r\n * [truncate](#truncateint-length--string-substring---)\r\n * [underscored](#underscored)\r\n * [upperCamelize](#uppercamelize)\r\n * [upperCaseFirst](#uppercasefirst)\r\n* [Extensions](#extensions)\r\n* [Tests](#tests)\r\n* [License](#license)\r\n\r\n## Why?\r\n\r\nIn part due to a lack of multibyte support (including UTF-8) across many of\r\nPHP's standard string functions. But also to offer an OO wrapper around the\r\n`mbstring` module's multibyte-compatible functions. Stringy handles some quirks,\r\nprovides additional functionality, and hopefully makes strings a little easier\r\nto work with!\r\n\r\n```php\r\n// Standard library\r\nstrtoupper('fòôbàř'); // 'FòôBàř'\r\nstrlen('fòôbàř'); // 10\r\n\r\n// mbstring\r\nmb_strtoupper('fòôbàř'); // 'FÒÔBÀŘ'\r\nmb_strlen('fòôbàř'); // '6'\r\n\r\n// Stringy\r\ns('fòôbàř')->toUpperCase(); // 'FÒÔBÀŘ'\r\ns('fòôbàř')->length(); // '6'\r\n```\r\n\r\n## Installation\r\n\r\nIf you're using Composer to manage dependencies, you can include the following\r\nin your composer.json file:\r\n\r\n```json\r\n\"require\": {\r\n \"danielstjules/stringy\": \"~2.1\"\r\n}\r\n```\r\n\r\nThen, after running `composer update` or `php composer.phar update`, you can\r\nload the class using Composer's autoloading:\r\n\r\n```php\r\nrequire 'vendor/autoload.php';\r\n```\r\n\r\nOtherwise, you can simply require the file directly:\r\n\r\n```php\r\nrequire_once 'path/to/Stringy/src/Stringy.php';\r\n```\r\n\r\nAnd in either case, I'd suggest using an alias.\r\n\r\n```php\r\nuse Stringy\\Stringy as S;\r\n```\r\n\r\nPlease note that Stringy relies on the `mbstring` PHP module for its underlying\r\nmultibyte support. This is a non-default, but very common module. For example,\r\nwith debian and ubuntu, it's included in libapache2-mod-php5, php5-cli, and\r\nphp5-fpm. For OSX users, it's a default for any version of PHP installed with\r\nhomebrew. If compiling PHP from scratch, it can be included with the\r\n`--enable-mbstring` flag.\r\n\r\n## OO and Chaining\r\n\r\nThe library offers OO method chaining, as seen below:\r\n\r\n```php\r\nuse Stringy\\Stringy as S;\r\necho S::create('fòô bàř')->collapseWhitespace()->swapCase(); // 'FÒÔ BÀŘ'\r\n```\r\n\r\n`Stringy\\Stringy` has a __toString() method, which returns the current string\r\nwhen the object is used in a string context, ie:\r\n`(string) S::create('foo') // 'foo'`\r\n\r\n## Implemented Interfaces\r\n\r\n`Stringy\\Stringy` implements the `IteratorAggregate` interface, meaning that\r\n`foreach` can be used with an instance of the class:\r\n\r\n``` php\r\n$stringy = S::create('fòôbàř');\r\nforeach ($stringy as $char) {\r\n echo $char;\r\n}\r\n// 'fòôbàř'\r\n```\r\n\r\nIt implements the `Countable` interface, enabling the use of `count()` to\r\nretrieve the number of characters in the string:\r\n\r\n``` php\r\n$stringy = S::create('fòô');\r\ncount($stringy); // 3\r\n```\r\n\r\nFurthermore, the `ArrayAccess` interface has been implemented. As a result,\r\n`isset()` can be used to check if a character at a specific index exists. And\r\nsince `Stringy\\Stringy` is immutable, any call to `offsetSet` or `offsetUnset`\r\nwill throw an exception. `offsetGet` has been implemented, however, and accepts\r\nboth positive and negative indexes. Invalid indexes result in an\r\n`OutOfBoundsException`.\r\n\r\n``` php\r\n$stringy = S::create('bàř');\r\necho $stringy[2]; // 'ř'\r\necho $stringy[-2]; // 'à'\r\nisset($stringy[-4]); // false\r\n\r\n$stringy[3]; // OutOfBoundsException\r\n$stringy[2] = 'a'; // Exception\r\n```\r\n\r\n## PHP 5.6 Creation\r\n\r\nAs of PHP 5.6, [`use function`](https://wiki.php.net/rfc/use_function) is\r\navailable for importing functions. Stringy exposes a namespaced function,\r\n`Stringy\\create`, which emits the same behaviour as `Stringy\\Stringy::create()`.\r\nIf running PHP 5.6, or another runtime that supports the `use function` syntax,\r\nyou can take advantage of an even simpler API as seen below:\r\n\r\n``` php\r\nuse function Stringy\\create as s;\r\n\r\n// Instead of: S::create('fòô bàř')\r\ns('fòô bàř')->collapseWhitespace()->swapCase();\r\n```\r\n\r\n## StaticStringy\r\n\r\nAll methods listed under \"Instance methods\" are available as part of a static\r\nwrapper. For StaticStringy methods, the optional encoding is expected to be the\r\nlast argument. The return value is not cast, and may thus be of type Stringy,\r\ninteger, boolean, etc.\r\n\r\n```php\r\nuse Stringy\\StaticStringy as S;\r\n\r\n// Translates to Stringy::create('fòôbàř', 'UTF-8')->slice(0, 3);\r\n// Returns a Stringy object with the string \"fòô\"\r\nS::slice('fòôbàř', 0, 3, 'UTF-8');\r\n```\r\n\r\n## Class methods\r\n\r\n##### create(mixed $str [, $encoding ])\r\n\r\nCreates a Stringy object and assigns both str and encoding properties\r\nthe supplied values. $str is cast to a string prior to assignment, and if\r\n$encoding is not specified, it defaults to mb_internal_encoding(). It\r\nthen returns the initialized object. Throws an InvalidArgumentException\r\nif the first argument is an array or object without a __toString method.\r\n\r\n```php\r\n$stringy = S::create('fòôbàř', 'UTF-8'); // 'fòôbàř'\r\n```\r\n\r\n## Instance Methods\r\n\r\nStringy objects are immutable. All examples below make use of PHP 5.6\r\nfunction importing, and PHP 5.4 short array syntax. They also assume the\r\nencoding returned by mb_internal_encoding() is UTF-8. For further details,\r\nsee the documentation for the create method above, as well as the notes\r\non PHP 5.6 creation.\r\n\r\n##### append(string $string)\r\n\r\nReturns a new string with $string appended.\r\n\r\n```php\r\ns('fòô')->append('bàř'); // 'fòôbàř'\r\n```\r\n\r\n##### at(int $index)\r\n\r\nReturns the character at $index, with indexes starting at 0.\r\n\r\n```php\r\ns('fòôbàř')->at(3); // 'b'\r\n```\r\n\r\n##### between(string $start, string $end [, int $offset])\r\n\r\nReturns the substring between $start and $end, if found, or an empty\r\nstring. An optional offset may be supplied from which to begin the\r\nsearch for the start string.\r\n\r\n```php\r\ns('{foo} and {bar}')->between('{', '}'); // 'foo'\r\n```\r\n\r\n##### camelize()\r\n\r\nReturns a camelCase version of the string. Trims surrounding spaces,\r\ncapitalizes letters following digits, spaces, dashes and underscores,\r\nand removes spaces, dashes, as well as underscores.\r\n\r\n```php\r\ns('Camel-Case')->camelize(); // 'camelCase'\r\n```\r\n\r\n##### chars()\r\n\r\nReturns an array consisting of the characters in the string.\r\n\r\n```php\r\ns('fòôbàř')->chars(); // ['f', 'ò', 'ô', 'b', 'à', 'ř']\r\n```\r\n\r\n##### collapseWhitespace()\r\n\r\nTrims the string and replaces consecutive whitespace characters with a\r\nsingle space. This includes tabs and newline characters, as well as\r\nmultibyte whitespace such as the thin space and ideographic space.\r\n\r\n```php\r\ns(' Ο συγγραφέας ')->collapseWhitespace(); // 'Ο συγγραφέας'\r\n```\r\n\r\n##### contains(string $needle [, boolean $caseSensitive = true ])\r\n\r\nReturns true if the string contains $needle, false otherwise. By default,\r\nthe comparison is case-sensitive, but can be made insensitive\r\nby setting $caseSensitive to false.\r\n\r\n```php\r\ns('Ο συγγραφέας είπε')->contains('συγγραφέας'); // true\r\n```\r\n\r\n##### containsAll(array $needles [, boolean $caseSensitive = true ])\r\n\r\nReturns true if the string contains all $needles, false otherwise. By\r\ndefault the comparison is case-sensitive, but can be made insensitive by\r\nsetting $caseSensitive to false.\r\n\r\n```php\r\ns('foo & bar')->containsAll(['foo', 'bar']); // true\r\n```\r\n\r\n##### containsAny(array $needles [, boolean $caseSensitive = true ])\r\n\r\nReturns true if the string contains any $needles, false otherwise. By\r\ndefault the comparison is case-sensitive, but can be made insensitive by\r\nsetting $caseSensitive to false.\r\n\r\n```php\r\ns('str contains foo')->containsAny(['foo', 'bar']); // true\r\n```\r\n\r\n##### countSubstr(string $substring [, boolean $caseSensitive = true ])\r\n\r\nReturns the number of occurrences of $substring in the given string.\r\nBy default, the comparison is case-sensitive, but can be made insensitive\r\nby setting $caseSensitive to false.\r\n\r\n```php\r\ns('Ο συγγραφέας είπε')->countSubstr('α'); // 2\r\n```\r\n\r\n##### dasherize()\r\n\r\nReturns a lowercase and trimmed string separated by dashes. Dashes are\r\ninserted before uppercase characters (with the exception of the first\r\ncharacter of the string), and in place of spaces as well as underscores.\r\n\r\n```php\r\ns('fooBar')->dasherize(); // 'foo-bar'\r\n```\r\n\r\n##### delimit(int $delimiter)\r\n\r\nReturns a lowercase and trimmed string separated by the given delimiter.\r\nDelimiters are inserted before uppercase characters (with the exception\r\nof the first character of the string), and in place of spaces, dashes,\r\nand underscores. Alpha delimiters are not converted to lowercase.\r\n\r\n```php\r\ns('fooBar')->delimit('::'); // 'foo::bar'\r\n```\r\n\r\n##### endsWith(string $substring [, boolean $caseSensitive = true ])\r\n\r\nReturns true if the string ends with $substring, false otherwise. By\r\ndefault, the comparison is case-sensitive, but can be made insensitive by\r\nsetting $caseSensitive to false.\r\n\r\n```php\r\ns('fòôbàř')->endsWith('bàř', true); // true\r\n```\r\n\r\n##### ensureLeft(string $substring)\r\n\r\nEnsures that the string begins with $substring. If it doesn't, it's prepended.\r\n\r\n```php\r\ns('foobar')->ensureLeft('http://'); // 'http://foobar'\r\n```\r\n\r\n##### ensureRight(string $substring)\r\n\r\nEnsures that the string begins with $substring. If it doesn't, it's appended.\r\n\r\n```php\r\ns('foobar')->ensureRight('.com'); // 'foobar.com'\r\n```\r\n\r\n##### first(int $n)\r\n\r\nReturns the first $n characters of the string.\r\n\r\n```php\r\ns('fòôbàř')->first(3); // 'fòô'\r\n```\r\n\r\n##### getEncoding()\r\n\r\nReturns the encoding used by the Stringy object.\r\n\r\n```php\r\ns('fòôbàř', 'UTF-8')->getEncoding(); // 'UTF-8'\r\n```\r\n\r\n##### hasLowerCase()\r\n\r\nReturns true if the string contains a lower case char, false otherwise.\r\n\r\n```php\r\ns('fòôbàř')->hasLowerCase(); // true\r\n```\r\n\r\n##### hasUpperCase()\r\n\r\nReturns true if the string contains an upper case char, false otherwise.\r\n\r\n```php\r\ns('fòôbàř')->hasUpperCase(); // false\r\n```\r\n\r\n##### htmlDecode()\r\n\r\nConvert all HTML entities to their applicable characters. An alias of\r\nhtml_entity_decode. For a list of flags, refer to\r\nhttp://php.net/manual/en/function.html-entity-decode.php\r\n\r\n```php\r\ns('&')->htmlDecode(); // '&'\r\n```\r\n\r\n##### htmlEncode()\r\n\r\nConvert all applicable characters to HTML entities. An alias of\r\nhtmlentities. Refer to http://php.net/manual/en/function.htmlentities.php\r\nfor a list of flags.\r\n\r\n```php\r\ns('&')->htmlEncode(); // '&'\r\n```\r\n\r\n##### humanize()\r\n\r\nCapitalizes the first word of the string, replaces underscores with\r\nspaces, and strips '_id'.\r\n\r\n```php\r\ns('author_id')->humanize(); // 'Author'\r\n```\r\n\r\n##### indexOf(string $needle [, $offset = 0 ]);\r\n\r\nReturns the index of the first occurrence of $needle in the string,\r\nand false if not found. Accepts an optional offset from which to begin\r\nthe search. A negative index searches from the end\r\n\r\n```php\r\ns('string')->indexOf('ing'); // 3\r\n```\r\n\r\n##### indexOfLast(string $needle [, $offset = 0 ]);\r\n\r\nReturns the index of the last occurrence of $needle in the string,\r\nand false if not found. Accepts an optional offset from which to begin\r\nthe search. Offsets may be negative to count from the last character\r\nin the string.\r\n\r\n```php\r\ns('foobarfoo')->indexOfLast('foo'); // 10\r\n```\r\n\r\n##### insert(int $index, string $substring)\r\n\r\nInserts $substring into the string at the $index provided.\r\n\r\n```php\r\ns('fòôbř')->insert('à', 4); // 'fòôbàř'\r\n```\r\n\r\n##### isAlpha()\r\n\r\nReturns true if the string contains only alphabetic chars, false otherwise.\r\n\r\n```php\r\ns('丹尼爾')->isAlpha(); // true\r\n```\r\n\r\n##### isAlphanumeric()\r\n\r\nReturns true if the string contains only alphabetic and numeric chars, false\r\notherwise.\r\n\r\n```php\r\ns('دانيال1')->isAlphanumeric(); // true\r\n```\r\n\r\n##### isBlank()\r\n\r\nReturns true if the string contains only whitespace chars, false otherwise.\r\n\r\n```php\r\ns(\"\\n\\t \\v\\f\")->isBlank(); // true\r\n```\r\n\r\n##### isHexadecimal()\r\n\r\nReturns true if the string contains only hexadecimal chars, false otherwise.\r\n\r\n```php\r\ns('A102F')->isHexadecimal(); // true\r\n```\r\n\r\n##### isJson()\r\n\r\nReturns true if the string is JSON, false otherwise.\r\n\r\n```php\r\ns('{\"foo\":\"bar\"}')->isJson(); // true\r\n```\r\n\r\n##### isLowerCase()\r\n\r\nReturns true if the string contains only lower case chars, false otherwise.\r\n\r\n```php\r\ns('fòôbàř')->isLowerCase(); // true\r\n```\r\n\r\n##### isSerialized()\r\n\r\nReturns true if the string is serialized, false otherwise.\r\n\r\n```php\r\ns('a:1:{s:3:\"foo\";s:3:\"bar\";}')->isSerialized(); // true\r\n```\r\n\r\n##### isUpperCase()\r\n\r\nReturns true if the string contains only upper case chars, false otherwise.\r\n\r\n```php\r\ns('FÒÔBÀŘ')->isUpperCase(); // true\r\n```\r\n\r\n##### last(int $n)\r\n\r\nReturns the last $n characters of the string.\r\n\r\n```php\r\ns('fòôbàř')->last(3); // 'bàř'\r\n```\r\n\r\n##### length()\r\n\r\nReturns the length of the string. An alias for PHP's mb_strlen() function.\r\n\r\n```php\r\ns('fòôbàř')->length(); // 6\r\n```\r\n\r\n##### lines()\r\n\r\nSplits on newlines and carriage returns, returning an array of Stringy\r\nobjects corresponding to the lines in the string.\r\n\r\n```php\r\ns(\"fòô\\r\\nbàř\\n\")->lines(); // ['fòô', 'bàř', '']\r\n```\r\n\r\n##### longestCommonPrefix(string $otherStr)\r\n\r\nReturns the longest common prefix between the string and $otherStr.\r\n\r\n```php\r\ns('foobar')->longestCommonPrefix('foobaz'); // 'fooba'\r\n```\r\n\r\n##### longestCommonSuffix(string $otherStr)\r\n\r\nReturns the longest common suffix between the string and $otherStr.\r\n\r\n```php\r\ns('fòôbàř')->longestCommonSuffix('fòrbàř'); // 'bàř'\r\n```\r\n\r\n##### longestCommonSubstring(string $otherStr)\r\n\r\nReturns the longest common substring between the string and $otherStr. In the\r\ncase of ties, it returns that which occurs first.\r\n\r\n```php\r\ns('foobar')->longestCommonSubstring('boofar'); // 'oo'\r\n```\r\n\r\n##### lowerCaseFirst()\r\n\r\nConverts the first character of the supplied string to lower case.\r\n\r\n```php\r\ns('Σ foo')->lowerCaseFirst(); // 'σ foo'\r\n```\r\n\r\n##### pad(int $length [, string $padStr = ' ' [, string $padType = 'right' ]])\r\n\r\nPads the string to a given length with $padStr. If length is less than\r\nor equal to the length of the string, no padding takes places. The default\r\nstring used for padding is a space, and the default type (one of 'left',\r\n'right', 'both') is 'right'. Throws an InvalidArgumentException if\r\n$padType isn't one of those 3 values.\r\n\r\n```php\r\ns('fòôbàř')->pad(9, '-/', 'left'); // '-/-fòôbàř'\r\n```\r\n\r\n##### padBoth(int $length [, string $padStr = ' ' ])\r\n\r\nReturns a new string of a given length such that both sides of the string\r\nstring are padded. Alias for pad() with a $padType of 'both'.\r\n\r\n```php\r\ns('foo bar')->padBoth(9, ' '); // ' foo bar '\r\n```\r\n\r\n##### padLeft(int $length [, string $padStr = ' ' ])\r\n\r\nReturns a new string of a given length such that the beginning of the\r\nstring is padded. Alias for pad() with a $padType of 'left'.\r\n\r\n```php\r\ns('foo bar')->padLeft(9, ' '); // ' foo bar'\r\n```\r\n\r\n##### padRight(int $length [, string $padStr = ' ' ])\r\n\r\nReturns a new string of a given length such that the end of the string is\r\npadded. Alias for pad() with a $padType of 'right'.\r\n\r\n```php\r\ns('foo bar')->padRight(10, '_*'); // 'foo bar_*_'\r\n```\r\n\r\n##### prepend(string $string)\r\n\r\nReturns a new string starting with $string.\r\n\r\n```php\r\ns('bàř')->prepend('fòô'); // 'fòôbàř'\r\n```\r\n\r\n##### regexReplace(string $pattern, string $replacement [, string $options = 'msr'])\r\n\r\nReplaces all occurrences of $pattern in $str by $replacement. An alias\r\nfor mb_ereg_replace(). Note that the 'i' option with multibyte patterns\r\nin mb_ereg_replace() requires PHP 5.6+ for correct results. This is due\r\nto a lack of support in the bundled version of Oniguruma in PHP < 5.6,\r\nand current versions of HHVM (3.8 and below).\r\n\r\n```php\r\ns('fòô ')->regexReplace('f[òô]+\\s', 'bàř', 'msr'); // 'bàř'\r\n```\r\n\r\n##### removeLeft(string $substring)\r\n\r\nReturns a new string with the prefix $substring removed, if present.\r\n\r\n```php\r\ns('fòôbàř')->removeLeft('fòô'); // 'bàř'\r\n```\r\n\r\n##### removeRight(string $substring)\r\n\r\nReturns a new string with the suffix $substring removed, if present.\r\n\r\n```php\r\ns('fòôbàř')->removeRight('bàř'); // 'fòô'\r\n```\r\n\r\n##### repeat(int $multiplier)\r\n\r\nReturns a repeated string given a multiplier. An alias for str_repeat.\r\n\r\n```php\r\ns('α')->repeat(3); // 'ααα'\r\n```\r\n\r\n##### replace(string $search, string $replacement)\r\n\r\nReplaces all occurrences of $search in $str by $replacement.\r\n\r\n```php\r\ns('fòô bàř fòô bàř')->replace('fòô ', ''); // 'bàř bàř'\r\n```\r\n\r\n##### reverse()\r\n\r\nReturns a reversed string. A multibyte version of strrev().\r\n\r\n```php\r\ns('fòôbàř')->reverse(); // 'řàbôòf'\r\n```\r\n\r\n##### safeTruncate(int $length [, string $substring = '' ])\r\n\r\nTruncates the string to a given length, while ensuring that it does not\r\nsplit words. If $substring is provided, and truncating occurs, the\r\nstring is further truncated so that the substring may be appended without\r\nexceeding the desired length.\r\n\r\n```php\r\ns('What are your plans today?')->safeTruncate(22, '...');\r\n// 'What are your plans...'\r\n```\r\n\r\n##### shuffle()\r\n\r\nA multibyte str_shuffle() function. It returns a string with its characters in\r\nrandom order.\r\n\r\n```php\r\ns('fòôbàř')->shuffle(); // 'àôřbòf'\r\n```\r\n\r\n##### slugify([, string $replacement = '-' ])\r\n\r\nConverts the string into an URL slug. This includes replacing non-ASCII\r\ncharacters with their closest ASCII equivalents, removing remaining\r\nnon-ASCII and non-alphanumeric characters, and replacing whitespace with\r\n$replacement. The replacement defaults to a single dash, and the string\r\nis also converted to lowercase.\r\n\r\n```php\r\ns('Using strings like fòô bàř')->slugify(); // 'using-strings-like-foo-bar'\r\n```\r\n\r\n##### startsWith(string $substring [, boolean $caseSensitive = true ])\r\n\r\nReturns true if the string begins with $substring, false otherwise.\r\nBy default, the comparison is case-sensitive, but can be made insensitive\r\nby setting $caseSensitive to false.\r\n\r\n```php\r\ns('FÒÔbàřbaz')->startsWith('fòôbàř', false); // true\r\n```\r\n\r\n##### slice(int $start [, int $end ])\r\n\r\nReturns the substring beginning at $start, and up to, but not including\r\nthe index specified by $end. If $end is omitted, the function extracts\r\nthe remaining string. If $end is negative, it is computed from the end\r\nof the string.\r\n\r\n```php\r\ns('fòôbàř')->slice(3, -1); // 'bà'\r\n```\r\n\r\n##### split(string $pattern [, int $limit ])\r\n\r\nSplits the string with the provided regular expression, returning an\r\narray of Stringy objects. An optional integer $limit will truncate the\r\nresults.\r\n\r\n```php\r\ns('foo,bar,baz')->split(',', 2); // ['foo', 'bar']\r\n```\r\n\r\n##### substr(int $start [, int $length ])\r\n\r\nReturns the substring beginning at $start with the specified $length.\r\nIt differs from the mb_substr() function in that providing a $length of\r\nnull will return the rest of the string, rather than an empty string.\r\n\r\n```php\r\ns('fòôbàř')->substr(2, 3); // 'ôbà'\r\n```\r\n\r\n##### surround(string $substring)\r\n\r\nSurrounds a string with the given substring.\r\n\r\n```php\r\ns(' ͜ ')->surround('ʘ'); // 'ʘ ͜ ʘ'\r\n```\r\n\r\n##### swapCase()\r\n\r\nReturns a case swapped version of the string.\r\n\r\n```php\r\ns('Ντανιλ')->swapCase(); // 'νΤΑΝΙΛ'\r\n```\r\n\r\n##### tidy()\r\n\r\nReturns a string with smart quotes, ellipsis characters, and dashes from\r\nWindows-1252 (commonly used in Word documents) replaced by their ASCII equivalents.\r\n\r\n```php\r\ns('“I see…”')->tidy(); // '\"I see...\"'\r\n```\r\n\r\n##### titleize([, array $ignore])\r\n\r\nReturns a trimmed string with the first letter of each word capitalized.\r\nAlso accepts an array, $ignore, allowing you to list words not to be\r\ncapitalized.\r\n\r\n```php\r\n$ignore = ['at', 'by', 'for', 'in', 'of', 'on', 'out', 'to', 'the'];\r\ns('i like to watch television')->titleize($ignore);\r\n// 'I Like to Watch Television'\r\n```\r\n\r\n##### toAscii()\r\n\r\nReturns an ASCII version of the string. A set of non-ASCII characters are\r\nreplaced with their closest ASCII counterparts, and the rest are removed\r\nunless instructed otherwise.\r\n\r\n```php\r\ns('fòôbàř')->toAscii(); // 'foobar'\r\n```\r\n\r\n##### toBoolean()\r\n\r\nReturns a boolean representation of the given logical string value.\r\nFor example, 'true', '1', 'on' and 'yes' will return true. 'false', '0',\r\n'off', and 'no' will return false. In all instances, case is ignored.\r\nFor other numeric strings, their sign will determine the return value.\r\nIn addition, blank strings consisting of only whitespace will return\r\nfalse. For all other strings, the return value is a result of a\r\nboolean cast.\r\n\r\n```php\r\ns('OFF')->toBoolean(); // false\r\n```\r\n\r\n##### toLowerCase()\r\n\r\nConverts all characters in the string to lowercase. An alias for PHP's\r\nmb_strtolower().\r\n\r\n```php\r\ns('FÒÔBÀŘ')->toLowerCase(); // 'fòôbàř'\r\n```\r\n\r\n##### toSpaces([, tabLength = 4 ])\r\n\r\nConverts each tab in the string to some number of spaces, as defined by\r\n$tabLength. By default, each tab is converted to 4 consecutive spaces.\r\n\r\n```php\r\ns(' String speech = \"Hi\"')->toSpaces(); // ' String speech = \"Hi\"'\r\n```\r\n\r\n##### toTabs([, tabLength = 4 ])\r\n\r\nConverts each occurrence of some consecutive number of spaces, as defined\r\nby $tabLength, to a tab. By default, each 4 consecutive spaces are\r\nconverted to a tab.\r\n\r\n```php\r\ns(' fòô bàř')->toTabs();\r\n// ' fòô bàř'\r\n```\r\n\r\n##### toTitleCase()\r\n\r\nConverts the first character of each word in the string to uppercase.\r\n\r\n```php\r\ns('fòô bàř')->toTitleCase(); // 'Fòô Bàř'\r\n```\r\n\r\n##### toUpperCase()\r\n\r\nConverts all characters in the string to uppercase. An alias for PHP's\r\nmb_strtoupper().\r\n\r\n```php\r\ns('fòôbàř')->toUpperCase(); // 'FÒÔBÀŘ'\r\n```\r\n\r\n##### trim([, string $chars])\r\n\r\nReturns a string with whitespace removed from the start and end of the\r\nstring. Supports the removal of unicode whitespace. Accepts an optional\r\nstring of characters to strip instead of the defaults.\r\n\r\n```php\r\ns(' fòôbàř ')->trim(); // 'fòôbàř'\r\n```\r\n\r\n##### trimLeft([, string $chars])\r\n\r\nReturns a string with whitespace removed from the start of the string.\r\nSupports the removal of unicode whitespace. Accepts an optional\r\nstring of characters to strip instead of the defaults.\r\n\r\n```php\r\ns(' fòôbàř ')->trimLeft(); // 'fòôbàř '\r\n```\r\n\r\n##### trimRight([, string $chars])\r\n\r\nReturns a string with whitespace removed from the end of the string.\r\nSupports the removal of unicode whitespace. Accepts an optional\r\nstring of characters to strip instead of the defaults.\r\n\r\n```php\r\ns(' fòôbàř ')->trimRight(); // ' fòôbàř'\r\n```\r\n\r\n##### truncate(int $length [, string $substring = '' ])\r\n\r\nTruncates the string to a given length. If $substring is provided, and\r\ntruncating occurs, the string is further truncated so that the substring\r\nmay be appended without exceeding the desired length.\r\n\r\n```php\r\ns('What are your plans today?')->truncate(19, '...'); // 'What are your pl...'\r\n```\r\n\r\n##### underscored()\r\n\r\nReturns a lowercase and trimmed string separated by underscores.\r\nUnderscores are inserted before uppercase characters (with the exception\r\nof the first character of the string), and in place of spaces as well as dashes.\r\n\r\n```php\r\ns('TestUCase')->underscored(); // 'test_u_case'\r\n```\r\n\r\n##### upperCamelize()\r\n\r\nReturns an UpperCamelCase version of the supplied string. It trims\r\nsurrounding spaces, capitalizes letters following digits, spaces, dashes\r\nand underscores, and removes spaces, dashes, underscores.\r\n\r\n```php\r\ns('Upper Camel-Case')->upperCamelize(); // 'UpperCamelCase'\r\n```\r\n\r\n##### upperCaseFirst()\r\n\r\nConverts the first character of the supplied string to upper case.\r\n\r\n```php\r\ns('σ foo')->upperCaseFirst(); // 'Σ foo'\r\n```\r\n\r\n## Extensions\r\n\r\nThe following is a list of libraries that extend Stringy:\r\n\r\n * [SliceableStringy](https://github.com/danielstjules/SliceableStringy):\r\nPython-like string slices in PHP\r\n * [SubStringy](https://github.com/TCB13/SubStringy):\r\nAdvanced substring methods\r\n\r\n## Tests\r\n\r\nFrom the project directory, tests can be ran using `phpunit`\r\n\r\n## License\r\n\r\nReleased under the MIT License - see `LICENSE.txt` for details.\r\n","google":"","note":"Don't delete this file! It's used internally to help with page regeneration."} \ No newline at end of file