{"id":17491912,"url":"https://github.com/tcb13/substringy","last_synced_at":"2025-04-22T20:15:38.292Z","repository":{"id":32985097,"uuid":"36611711","full_name":"TCB13/SubStringy","owner":"TCB13","description":"Advanced SubString manipulation for Stringy, the string manipulation library.","archived":false,"fork":false,"pushed_at":"2017-10-10T16:41:17.000Z","size":20,"stargazers_count":17,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-22T20:15:32.527Z","etag":null,"topics":["multibyte","php","string-manipulation","strings","substrings"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TCB13.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-31T16:27:03.000Z","updated_at":"2020-08-06T21:50:31.000Z","dependencies_parsed_at":"2022-08-24T14:23:18.042Z","dependency_job_id":null,"html_url":"https://github.com/TCB13/SubStringy","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TCB13%2FSubStringy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TCB13%2FSubStringy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TCB13%2FSubStringy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TCB13%2FSubStringy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TCB13","download_url":"https://codeload.github.com/TCB13/SubStringy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250316066,"owners_count":21410476,"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":["multibyte","php","string-manipulation","strings","substrings"],"created_at":"2024-10-19T08:06:02.688Z","updated_at":"2025-04-22T20:15:38.267Z","avatar_url":"https://github.com/TCB13.png","language":"PHP","readme":"A PHP SubString manipulation library with multibyte support that extends Stringy. Offers OO method\nchaining. Tested and compatible with PHP 5.4+ and HHVM.\n\nThis library extends and adds SubString functionality to `danielstjules/Stringy` you should check it's [documentation](https://github.com/danielstjules/Stringy/blob/master/README.md) for methods inherited by SubStringy.\n\n[![Build Status](https://api.travis-ci.org/tcb13/SubStringy.svg?branch=master)](https://travis-ci.org/tcb13/SubStringy)\n\n* [Installation](#installation)\n* [OO and Chaining](#oo-and-chaining)\n* [Use as a Trait](#use-as-a-trait)\n* [Implemented Interfaces](#implemented-interfaces)\n* [PHP 5.6 Creation](#php-56-creation)\n* [Methods](#methods)\n    * [substringAfterFirst](#substringafterfirst)\n    * [substringAfterLast](#substringafterlast)\n    * [substringBeforeFirst](#substringbeforefirst)\n    * [substringBeforeLast](#substringbeforelast)\n    * [substringBetween](#substringbetween)\n    * [substringCount](#substringcount)\n* [Links](#links)\n* [Tests](#tests)\n* [License](#license)\n\n## Installation\n\nIf you're using Composer to manage dependencies, you can include the following\nin your composer.json file:\n\n```json\n{\n    \"require\": {\n        \"danielstjules/stringy\": \"^3.1\",\n        \"tcb13/substringy\": \"^1.0\"\n    }\n}\n```\n\nThen, after running `composer update` or `php composer.phar update`, you can\nload the class using Composer's autoloading:\n\n```php\nrequire 'vendor/autoload.php';\n```\n\nOtherwise, you can simply require the file directly:\n\n```php\nrequire_once 'path/to/SubStringy/src/SubStringy.php';\n```\n\nAnd in either case, I'd suggest using an alias.\n\n```php\nuse SubStringy\\SubStringy as S;\n```\n\n## OO and Chaining\n\nThe library offers OO method chaining, as seen below:\n\n```php\nuse Stringy\\Stringy as S;\necho S::create('Fòô     Bàř', 'UTF-8')-\u003ecollapseWhitespace()-\u003eswapCase();  // 'fÒÔ bÀŘ'\n```\n\n`Stringy\\Stringy` has a __toString() method, which returns the current string\nwhen the object is used in a string context, ie:\n`(string) S::create('foo')  // 'foo'`\n\n## Use as a Trait\n\nThe library also offers the possibility to be used a `trait`. With this trait you can build your own abstraction of `danielstjules/Stringy` and combine multiple extensions:\n\n```php\nnamespace Vendor\\YourPackage;\n\nuse Stringy\\Stringy;\nuse SubStringy\\SubStringyTrait;\nuse SliceableStringy\\SliceableStringyTrait;\n\nclass MyStringy extends Stringy\n{\n    use SubStringyTrait;\n    use SliceableStringyTrait;\n}\n```\n\nOn the example bellow we can use `MyStringy` to create `Stringy` objects enhanced with the functionality of both `SubStringy` and `SliceableStringy`:\n\n```php\nuse YourPackage\\MyStringy as S;\n$sliceableSubstring = S::create('What are your plans today?')-\u003esubstringAfterFirst('plans ');\necho $sliceableSubstring['4:6'];\n```\n\n## Implemented Interfaces\n\n`SubStringy\\SubStringy` implements the `IteratorAggregate` interface, meaning that\n`foreach` can be used with an instance of the class:\n\n``` php\n$stringy = S::create('Fòô Bàř', 'UTF-8');\nforeach ($stringy as $char) {\n    echo $char;\n}\n// 'Fòô Bàř'\n```\n\nIt implements the `Countable` interface, enabling the use of `count()` to\nretrieve the number of characters in the string:\n\n``` php\n$stringy = S::create('Fòô', 'UTF-8');\ncount($stringy);  // 3\n```\n\nFurthermore, the `ArrayAccess` interface has been implemented. As a result,\n`isset()` can be used to check if a character at a specific index exists. And\nsince `Stringy\\Stringy` is immutable, any call to `offsetSet` or `offsetUnset`\nwill throw an exception. `offsetGet` has been implemented, however, and accepts\nboth positive and negative indexes. Invalid indexes result in an\n`OutOfBoundsException`.\n\n``` php\n$stringy = S::create('Bàř', 'UTF-8');\necho $stringy[2];     // 'ř'\necho $stringy[-2];    // 'à'\nisset($stringy[-4]);  // false\n\n$stringy[3];          // OutOfBoundsException\n$stringy[2] = 'a';    // Exception\n```\n\n## PHP 5.6 Creation\n\nAs of PHP 5.6, [`use function`](https://wiki.php.net/rfc/use_function) is\navailable for importing functions. SubStringy exposes a namespaced function,\n`SubStringy\\create`, which emits the same behaviour as `SubStringy\\SubStringy::create()`.\nIf running PHP 5.6, or another runtime that supports the `use function` syntax,\nyou can take advantage of an even simpler API as seen below:\n\n``` php\nuse function SubStringy\\create as s;\n\n// Instead of: S::create('Fòô     Bàř', 'UTF-8')\ns('Fòô     Bàř', 'UTF-8')-\u003ecollapseWhitespace()-\u003eswapCase();\n```\n\n## Methods\n\nAll methods that return a SubStringy object or string do not modify the original. SubStringy objects are immutable.\n\nSince this library extends and adds SubString functionality to `danielstjules/Stringy` you should check it's documentation (https://github.com/danielstjules/Stringy/blob/master/README.md) for methods that can also be transparently used when working with SubStringy.\n\n*Note: If `$encoding` is not given, it defaults to `mb_internal_encoding()`.*\n\n#### substringAfterFirst\n\n$stringy-\u003esubstringAfterFirst(string $separator)\n\nGets the substring after the first occurrence of a separator. If no match is found returns false.\n\n```php\nS::create('What are your plans today?')-\u003esubstringAfterFirst('plans ');\n```\n\n#### substringAfterLast\n\n$stringy-\u003esubstringAfterLast(string $separator)\n\nGets the substring after the last occurrence of a separator. If no match is found returns false.\n\n```php\nS::create('This is a String. How cool can a String be after all?')-\u003esubstringAfterLast('String ');\n```\n\n#### substringBeforeFirst\n\n$stringy-\u003esubstringBeforeFirst(string $separator)\n\nGets the substring before the first occurrence of a separator. If no match is found returns false.\n\n```php\nS::create('What are your plans today?')-\u003esubstringBeforeFirst(' plans');\n```\n\n#### substringBeforeLast\n\n$stringy-\u003esubstringBeforeLast(string $separator)\n\nGets the substring before the last occurrence of a separator. If no match is found returns false.\n\n```php\nS::create('What are your plans today? Any plans for tomorrow?')-\u003esubstringBeforeLast(' plans');\n```\n\n#### substringBetween\n\n$stringy-\u003esubstringBetween(string $start, string $end)\n\nExtracts a substring from between two substrings present on the current string.\n\n```php\nS::create('What are your plans today?')-\u003esubstringBetween('your ', ' today');\n```\n\n#### substringCount\n\n$stringy-\u003esubstringCount(string $substr)\n\nCount the number of substring occurrences on the current string \n\n```php\nS::create('how are you? are you sure you are ok?')-\u003esubstringCount('are');\n```\n\n## Links\n\nThe following is a list of libraries that extend Stringy:\n\n * [SliceableStringy](https://github.com/danielstjules/SliceableStringy):\nPython-like string slices in PHP\n\n## Tests\n\nFrom the project directory, tests can be ran using `phpunit`\n\n## License\n\nReleased under the MIT License - see `LICENSE.txt` for details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftcb13%2Fsubstringy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftcb13%2Fsubstringy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftcb13%2Fsubstringy/lists"}