{"id":14966331,"url":"https://github.com/yiisoft/strings","last_synced_at":"2025-05-16T14:05:54.031Z","repository":{"id":34649643,"uuid":"182071881","full_name":"yiisoft/strings","owner":"yiisoft","description":"String helper methods and an inflector","archived":false,"fork":false,"pushed_at":"2025-02-09T16:31:10.000Z","size":353,"stargazers_count":48,"open_issues_count":6,"forks_count":17,"subscribers_count":21,"default_branch":"2.x","last_synced_at":"2025-05-11T17:30:49.915Z","etag":null,"topics":["hacktoberfest","inflector","numerical","pattern-matching","string","yii3"],"latest_commit_sha":null,"homepage":"https://www.yiiframework.com/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yiisoft.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"open_collective":"yiisoft","github":["yiisoft"]}},"created_at":"2019-04-18T11:02:52.000Z","updated_at":"2025-05-09T10:40:04.000Z","dependencies_parsed_at":"2023-12-13T03:36:11.834Z","dependency_job_id":"673a89c0-3c76-4547-94e9-55dba13b920c","html_url":"https://github.com/yiisoft/strings","commit_stats":{"total_commits":203,"total_committers":26,"mean_commits":"7.8076923076923075","dds":0.5615763546798029,"last_synced_commit":"fccb0ef70340630546af7f6156eaffad1c3a5d5b"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fstrings","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fstrings/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fstrings/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fstrings/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yiisoft","download_url":"https://codeload.github.com/yiisoft/strings/tar.gz/refs/heads/2.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254460288,"owners_count":22074848,"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":["hacktoberfest","inflector","numerical","pattern-matching","string","yii3"],"created_at":"2024-09-24T13:36:13.987Z","updated_at":"2025-05-16T14:05:54.008Z","avatar_url":"https://github.com/yiisoft.png","language":"PHP","funding_links":["https://opencollective.com/yiisoft","https://github.com/sponsors/yiisoft"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/yiisoft\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://yiisoft.github.io/docs/images/yii_logo.svg\" height=\"100px\" alt=\"Yii\"\u003e\n    \u003c/a\u003e\n    \u003ch1 align=\"center\"\u003eYii Strings\u003c/h1\u003e\n    \u003cbr\u003e\n\u003c/p\u003e\n\n[![Latest Stable Version](https://poser.pugx.org/yiisoft/strings/v)](https://packagist.org/packages/yiisoft/strings)\n[![Total Downloads](https://poser.pugx.org/yiisoft/strings/downloads)](https://packagist.org/packages/yiisoft/strings)\n[![Build status](https://github.com/yiisoft/strings/actions/workflows/build.yml/badge.svg)](https://github.com/yiisoft/strings/actions/workflows/build.yml)\n[![Code coverage](https://codecov.io/gh/yiisoft/strings/graph/badge.svg?token=GEPMBAHNCX)](https://codecov.io/gh/yiisoft/strings)\n[![Mutation testing badge](https://img.shields.io/endpoint?style=flat\u0026url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Fstrings%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/strings/master)\n[![static analysis](https://github.com/yiisoft/strings/workflows/static%20analysis/badge.svg)](https://github.com/yiisoft/strings/actions?query=workflow%3A%22static+analysis%22)\n[![type-coverage](https://shepherd.dev/github/yiisoft/strings/coverage.svg)](https://shepherd.dev/github/yiisoft/strings)\n\nThe package provides:\n\n- `StringHelper` that has static methods to work with strings;\n- `NumericHelper` that has static methods to work with numeric strings;\n- `Inflector` provides methods such as `toPlural()` or `toSlug()` that derive a new string based on the string given;\n- `WildcardPattern` is a shell wildcard pattern to match strings against;\n- `CombinedRegexp` is a wrapper that optimizes multiple regular expressions matching and\n  `MemoizedCombinedRegexp` is a decorator that caches results of `CombinedRegexp` to speed up matching.\n\n## Requirements\n\n- PHP 8.1 or higher.\n- `mbstring` PHP extension.\n\n## Installation\n\nThe package could be installed with [Composer](https://getcomposer.org):\n\n```shell\ncomposer require yiisoft/strings\n```\n\n## StringHelper usage\n\nString helper methods are static so usage is like the following:\n\n```php\necho \\Yiisoft\\Strings\\StringHelper::countWords('Strings are cool!'); // 3\n```\n\nOverall the helper has the following method groups.\n\n### Bytes\n\n- byteLength\n- byteSubstring\n\n### File paths\n\n- baseName\n- directoryName\n\n### Substrings\n\n- substring\n- replaceSubstring\n- startsWith\n- startsWithIgnoringCase\n- endsWith\n- endsWithIgnoringCase\n- findBetween\n- findBetweenFirst\n- findBetweenLast\n\n### Truncation\n\n- truncateBegin\n- truncateMiddle\n- truncateEnd\n- truncateWords\n- trim\n- ltrim\n- rtrim\n\n### Counting\n\n- length\n- countWords\n\n### Lowercase and uppercase\n\n- lowercase\n- uppercase\n- uppercaseFirstCharacter\n- uppercaseFirstCharacterInEachWord\n\n### URL friendly base64\n\n- base64UrlEncode\n- base64UrlDecode\n\n### Other\n\n- matchAnyRegex\n- parsePath\n- split\n\n## NumericHelper usage\n\nNumeric helper methods are static so usage is like the following:\n\n```php\necho \\Yiisoft\\Strings\\NumericHelper::toOrdinal(3); // 3rd\n```\n\nThe following methods are available:\n\n- toOrdinal\n- normalize\n- isInteger\n\n## Inflector usage\n\n```php\necho (new \\Yiisoft\\Strings\\Inflector())\n    -\u003ewithoutIntl()\n    -\u003etoSlug('Strings are cool!'); // strings-are-cool\n```\n\nOverall the inflector has the following method groups.\n\n### Plurals and singulars\n\n- toPlural\n- toSingular\n\n### Transliteration\n\n- toTransliterated\n\n### Case conversion\n\n- pascalCaseToId\n- toPascalCase\n- toCamelCase\n\n### Words and sentences\n\n- toSentence\n- toWords\n- toHumanReadable\n\n### Classes and database tables\n\n- classToTable\n- tableToClass\n\n### URLs\n\n- toSlug\n\n## WildcardPattern usage\n\n`WildcardPattern` allows a simple POSIX-style string matching.\n\n```php\nuse \\Yiisoft\\Strings\\WildcardPattern;\n\n$startsWithTest = new WildcardPattern('test*');\nif ($startsWithTest-\u003ematch('testIfThisIsTrue')) {\n    echo 'It starts with \"test\"!';\n}\n```\n\nThe following characters are special in the pattern:\n\n- `\\` escapes other special characters if usage of escape character is not turned off.\n- `*` matches any string, including the empty string, except delimiters (`/` and `\\` by default).\n- `**` matches any string, including the empty string and delimiters.\n- `?` matches any single character.\n- `[seq]` matches any character in seq.\n- `[a-z]` matches any character from a to z.\n- `[!seq]` matches any character not in seq.\n- `[[:alnum:]]` matches [POSIX style character classes](https://www.php.net/manual/en/regexp.reference.character-classes.php).\n\n`ignoreCase()` could be called before doing a `match()` to get a case-insensitive match:\n\n```php\nuse \\Yiisoft\\Strings\\WildcardPattern;\n\n$startsWithTest = new WildcardPattern('test*');\nif ($startsWithTest\n    -\u003eignoreCase()\n    -\u003ematch('tEStIfThisIsTrue')) {\n    echo 'It starts with \"test\"!';\n}\n```\n\n## CombinedRegexp usage\n\n`CombinedRegexp` optimizes matching multiple regular expressions.\n\n```php\nuse \\Yiisoft\\Strings\\CombinedRegexp;\n\n$patterns = [\n    'first',\n    'second',\n    '^a\\d$',\n];\n$regexp = new CombinedRegexp($patterns, 'i');\n$regexp-\u003ematches('a5'); // true – matches the third pattern\n$regexp-\u003ematches('A5'); // true – matches the third pattern because of `i` flag that is applied to all regular expressions\n$regexp-\u003egetMatchingPattern('a5'); // '^a\\d$' – the pattern that matched\n$regexp-\u003egetMatchingPatternPosition('a5'); // 2 – the index of the pattern in the array\n$regexp-\u003egetCompiledPattern(); // '~(?|first|second()|^a\\d$()())~'\n```\n\n## MemoizedCombinedRegexp usage\n\n`MemoizedCombinedRegexp` caches results of `CombinedRegexp` in memory.\nIt is useful when the same incoming string are matching multiple times or different methods of `CombinedRegexp` are called.\n\n```php\nuse \\Yiisoft\\Strings\\CombinedRegexp;\nuse \\Yiisoft\\Strings\\MemoizedCombinedRegexp;\n\n$patterns = [\n    'first',\n    'second',\n    '^a\\d$',\n];\n$regexp = new MemoizedCombinedRegexp(new CombinedRegexp($patterns, 'i'));\n$regexp-\u003ematches('a5'); // Fires `preg_match` inside the `CombinedRegexp`.\n$regexp-\u003ematches('first'); // Fires `preg_match` inside the `CombinedRegexp`.\n$regexp-\u003ematches('a5'); // Does not fire `preg_match` inside the `CombinedRegexp` because the result is cached.\n$regexp-\u003egetMatchingPattern('a5'); // The result is cached so no `preg_match` is fired.\n$regexp-\u003egetMatchingPatternPosition('a5'); // The result is cached so no `preg_match` is fired.\n\n// The following code fires only once matching mechanism.\nif ($regexp-\u003ematches('second')) {\n    echo sprintf(\n        'Matched the pattern \"%s\" which is on the position \"%s\" in the expressions list.',\n        $regexp-\u003egetMatchingPattern('second'),\n        $regexp-\u003egetMatchingPatternPosition('second'),\n    );\n}\n```\n\n## Documentation\n\n- [Internals](docs/internals.md)\n\nIf you need help or have a question, the [Yii Forum](https://forum.yiiframework.com/c/yii-3-0/63) is a good place for that.\nYou may also check out other [Yii Community Resources](https://www.yiiframework.com/community).\n\n## License\n\nThe Yii Strings is free software. It is released under the terms of the BSD License.\nPlease see [`LICENSE`](./LICENSE.md) for more information.\n\nMaintained by [Yii Software](https://www.yiiframework.com/).\n\n## Support the project\n\n[![Open Collective](https://img.shields.io/badge/Open%20Collective-sponsor-7eadf1?logo=open%20collective\u0026logoColor=7eadf1\u0026labelColor=555555)](https://opencollective.com/yiisoft)\n\n## Follow updates\n\n[![Official website](https://img.shields.io/badge/Powered_by-Yii_Framework-green.svg?style=flat)](https://www.yiiframework.com/)\n[![Twitter](https://img.shields.io/badge/twitter-follow-1DA1F2?logo=twitter\u0026logoColor=1DA1F2\u0026labelColor=555555?style=flat)](https://twitter.com/yiiframework)\n[![Telegram](https://img.shields.io/badge/telegram-join-1DA1F2?style=flat\u0026logo=telegram)](https://t.me/yii3en)\n[![Facebook](https://img.shields.io/badge/facebook-join-1DA1F2?style=flat\u0026logo=facebook\u0026logoColor=ffffff)](https://www.facebook.com/groups/yiitalk)\n[![Slack](https://img.shields.io/badge/slack-join-1DA1F2?style=flat\u0026logo=slack)](https://yiiframework.com/go/slack)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiisoft%2Fstrings","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyiisoft%2Fstrings","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiisoft%2Fstrings/lists"}