{"id":21458763,"url":"https://github.com/robclancy/string","last_synced_at":"2026-03-12T21:03:47.702Z","repository":{"id":7328705,"uuid":"8649487","full_name":"robclancy/string","owner":"robclancy","description":"A PHP library to manipulate strings via a string object similar to other languages","archived":false,"fork":false,"pushed_at":"2013-04-09T01:42:42.000Z","size":132,"stargazers_count":20,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-10-13T13:45:47.401Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/robclancy.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":"2013-03-08T11:20:25.000Z","updated_at":"2023-07-31T23:38:53.000Z","dependencies_parsed_at":"2022-08-28T14:12:52.561Z","dependency_job_id":null,"html_url":"https://github.com/robclancy/string","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/robclancy/string","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robclancy%2Fstring","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robclancy%2Fstring/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robclancy%2Fstring/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robclancy%2Fstring/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robclancy","download_url":"https://codeload.github.com/robclancy/string/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robclancy%2Fstring/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30444292,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-12T20:23:30.529Z","status":"ssl_error","status_checked_at":"2026-03-12T20:23:14.027Z","response_time":114,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2024-11-23T06:24:03.519Z","updated_at":"2026-03-12T21:03:47.685Z","avatar_url":"https://github.com/robclancy.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# String\n\nA PHP library to manipulate strings via a string object similar to other languages.\n\nThis library is designed as an alternative way to using PHP's inconsistant string functions without resorting to a simple wrapper. Basically a string object like you find in other languages. Also with a `str` function to make things a little shorter/easier and hide the longer `new String` when working with strings a lot.\n\nThis library has 2 dependencies: [oodle/inflect](https://github.com/oodle/inflect) and [patchwork/utf8](https://github.com/nicolas-grekas/Patchwork-UTF8)\n\n## Installation and Setup\nTo install add the following to your `composer.json` file:\n\n```json\n\"robclancy/string\": \"dev-master\"\n```\n\nThen you can use it out of the box directly with `RobClancy\\String\\String` or `str`. Alternatively create an alias like follows...\n\nNative:\n```php\nclass_alias('RobClancy\\String\\String', 'String');\n```\n\nLaravel, add to your aliases array in `app/config/app.php`:\n```php\n'String' =\u003e 'RobClancy\\String\\String',\n```\n\n## Examples Note: some of these aren't implemented yet, this package won't be ready for use until I write all the tests\n\n### Class name to table name\n\n```php\nclass UserGroup {\n\t\n\tpublic function getTable()\n\t{\n\t\t// We might want to point to the plural, snake case version of this class\n\t\t$class = new String(__CLASS__);\n\n\t\t// Snake case and split\n\t\t$words = $class-\u003esnake()-\u003esplit('_');\n\n\t\t// Pluralize last word\n\t\t// Note: at a later stage I might have an array object which will be used here to do $words-\u003elast()-\u003eplural();\n\t\t$words[count($word)-1]-\u003eplural();\n\n\t\t// Now return it joined back up\n\t\treturn String::join($words, '_');\n\t}\n}\n```\n\n### Ruby styled string replace and python styled slicing\n\n```php\n\n$string = new String('Jason made Basset, it is pretty cool I hear, vote 1 Jason!!');\n\n// String replace, the same as doing the key as $search and the value as $replace in $string-\u003ereplace($search, $value)\n$string['Jason'] = 'Jason Lewis';\n$string['Basset'] = 'Basset (Better Asset Management)';\n\n// We now want to change the 1 into 9001 but because the array notation here is overloaded to do python style slicing\n// and ruby style replacing we need to force it to the replace, we do this simply by starting the replace with 'r|'\n$string['r|1'] = 9001;\n\n// Lastly let's clean it up and make it end with a single !\n$string-\u003efinish('!');\n// or\n$string['!!'] = '!';\n// or\n$string-\u003eslice(0, -1);\n// or the same as above with python syntax.\n$string = $string[':-1'];\n\necho $string;\n// Outputs: \"Jason Lewis made Basset (Better Asset Management), it is pretty cool I hear, vote 9001 Jason Lewis!\"\n\n// Just another example of slicing with python\n$string = new String('I like pizza :D');\n$pizza = $string['7:-3'];\necho $pizza; // pizza\n\n```\n\n### Basic and quick validation with exceptions\n\n```php\n\n$string = 'Love for laravel \u003c3';\n$string-\u003estartsWith('Love');\t// true\n$string-\u003econtains('something'); // false\n$string-\u003eendsWith('\u003c3');\t\t// true\n$string-\u003eis('No love for laravel'); // obviously returns false!\n\n// Now to show with and without exceptions\n$string = new String('not_an_email');\n$string-\u003eisEmail(); // This will return false\n\n$string-\u003euseExceptions(true);\n$string-\u003eisEmail(); // This will now throw an exception\n\n// But calling that method is too verbose, so you can use a shortcut on string creation by passing true as the second argument\n$string = new String('still not an email', true);\n\n// Now any check will throw an exception so you can do quick checking and chain it like the following\ntry\n{\n\t// String must be an email to do with gmail and contain the word awesome\n\t$string-\u003eisEmail()-\u003eendsWith('@gmail.com')-\u003econtains('awesome');\n}\ncatch (StringException $e) // TODO: change this to whatever I call the exceptions\n{\n\t// failed\n}\n\n// Also you can globally set the exceptions flag to be used if one is not specified, defaults to false\nString::throwExceptions(true);\n```\n\n### Iteration\n\n```php\n\n$string = new String('It\\'s Saturday, I shouldn\\'t be working on this and drinking or something');\n\n// You can loop over the string chracter by character\n// Let's make the first letter of each word a capital just 'cause\n$previousSpace = false;\nforeach ($string AS $offset =\u003e $char)\n{\n\tif ($char-\u003eis(' '))\n\t{\n\t\t$previousSpace = true;\n\t\tcontinue;\n\t}\n\n\tif ($previousSpace)\n\t{\n\t\t$string[$offset] = $char-\u003eupper();\n\t}\n\n\t$previousSpace = false;\n}\n\necho $string; // It\\'s Saturday, I Shouldn\\'t Be Working On This And Drinking Or Something\n\n// We can do your usual splits, however in this case it splits into String objects like you would expect\n$words = $string-\u003esplit(' '); // normal array\n\n// Now let's do the same change as above but instead on each word, easier this time\nforeach ($words AS $key =\u003e $word)\n{\n\t$words[$key] = $word-\u003eupperFirst();\n}\n\n// Basically an alias for implode here\n$string = String::join($words, ' ');\necho $string; // It\\'s Saturday, I Shouldn\\'t Be Working On This And Drinking Or Something\n```\n\n\n[![Build Status](https://secure.travis-ci.org/robclancy/string.png)](http://travis-ci.org/robclancy/string)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobclancy%2Fstring","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobclancy%2Fstring","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobclancy%2Fstring/lists"}