{"id":33018424,"url":"https://github.com/hoaproject/String","last_synced_at":"2025-11-16T14:00:36.608Z","repository":{"id":32907013,"uuid":"36501876","full_name":"hoaproject/String","owner":"hoaproject","description":"The Hoa\\String library (deprecated by Hoa\\Ustring).","archived":true,"fork":false,"pushed_at":"2017-01-12T13:03:07.000Z","size":109,"stargazers_count":7,"open_issues_count":0,"forks_count":2,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-10-18T23:45:24.080Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://hoa-project.net/","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/hoaproject.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-05-29T12:03:06.000Z","updated_at":"2023-11-11T02:46:36.000Z","dependencies_parsed_at":"2022-07-22T04:47:55.701Z","dependency_job_id":null,"html_url":"https://github.com/hoaproject/String","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/hoaproject/String","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoaproject%2FString","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoaproject%2FString/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoaproject%2FString/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoaproject%2FString/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hoaproject","download_url":"https://codeload.github.com/hoaproject/String/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoaproject%2FString/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":284719042,"owners_count":27052182,"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","status":"online","status_checked_at":"2025-11-16T02:00:05.974Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":"2025-11-13T18:00:39.568Z","updated_at":"2025-11-16T14:00:36.601Z","avatar_url":"https://github.com/hoaproject.png","language":"PHP","funding_links":[],"categories":["字符串","Text and Numbers","字符串( Strings )","Strings","字符串 Strings"],"sub_categories":[],"readme":"![Hoa](http://static.hoa-project.net/Image/Hoa_small.png)\n\nHoa is a **modular**, **extensible** and **structured** set of PHP libraries.\nMoreover, Hoa aims at being a bridge between industrial and research worlds.\n\n# Hoa\\String ![state](http://central.hoa-project.net/State/String)\n\nThis library allows to manipulate UTF-8 strings easily with some search\nalgorithms.\n\n## Warning\n\nThis library is deprecated, and doesn't support `php \u003e= 7` because of new\nreserved keyword `string`, please use\n[`Hoa\\Ustring`](http://central.hoa-project.net/Resource/Library/Ustring).\n\n## Installation\n\nWith [Composer](http://getcomposer.org/), to include this library into your\ndependencies, you need to require\n[`hoa/string`](https://packagist.org/packages/hoa/string):\n\n```json\n{\n    \"require\": {\n        \"hoa/string\": \"~2.0\"\n    }\n}\n```\n\nPlease, read the website to [get more informations about how to\ninstall](http://hoa-project.net/Source.html).\n\n## Quick usage\n\nWe propose a quick overview of two usages: manipulate UTF-8 strings and one\nsearch algorithm.\n\n### Natural UTF-8 strings manipulation\n\nThe `Hoa\\String\\String` class allows to manipulate easily UTF-8 strings in a\nvery natural way. This class implements the `\\ArrayAccess`, `\\Countable` and\n`\\IteratorAggregate` interfaces. We will use the following examples:\n\n```php\n$french   = new Hoa\\String\\String('Je t\\'aime');\n$arabic   = new Hoa\\String\\String('أحبك');\n$japanese = new Hoa\\String\\String('私はあなたを愛して');\n```\n\nTo get the first character, we will do:\n\n```php\nvar_dump(\n    $french[0],  // string(1) \"J\"\n    $arabic[0],  // string(2) \"أ\"\n    $japanese[0] // string(3) \"私\"\n);\n```\n\nAnd to get the last character, we will do `[-1]`. It supports unbounded (and\nmodulo) indexes.\n\nWe note that it cares about text **direction**. Look at `$arabic[0]`, it returns\n`أ` and not `ك`. To get the direction, we can use the\n`Hoa\\String\\String::getDirection` method (which call the\n`Hoa\\String\\String::getCharDirection` static method), it returns either\n`Hoa\\String\\String::LTR` (`0`) or `Hoa\\String\\String::RTL` (`1`):\n\n```php\nvar_dump(\n    $french-\u003egetDirection(),  // int(0)\n    $arabic-\u003egetDirection(),  // int(1)\n    $japanese-\u003egetDirection() // int(0)\n);\n```\n\nText direction is also important for the `append`, `prepend`, `pad`… methods on\n`Hoa\\String\\String` for example. \n\nTo get the length of a string, we can use the `count` function:\n\n```php\nvar_dump(\n    count($french),  // int(9)\n    count($arabic),  // int(4)\n    count($japanese) // int(9)\n);\n```\n\nWe are also able to iterate over the string:\n\n```php\nforeach ($arabic as $letter) {\n    var_dump($letter);\n}\n\n/**\n * Will output:\n *     string(2) \"أ\"\n *     string(2) \"ح\"\n *     string(2) \"ب\"\n *     string(2) \"ك\"\n */\n```\n\nAgain, text direction is useful here. For `$arabic`, the iteration is done from\nright to left.\n\nSome static methods are helpful, such as `fromCode`, `toCode` or `isUtf8` on\n`Hoa\\String\\String`:\n\n```php\nvar_dump(\n    Hoa\\String\\String::fromCode(0x1a9), // string(2) \"Ʃ\"\n    Hoa\\String\\String::toCode('Ʃ'),     // int(425) == 0x1a9\n    Hoa\\String\\String::isUtf8('Ʃ')      // bool(true)\n);\n```\n\nWe can also transform any text into ASCII:\n\n```php\n$emoji = new Hoa\\String\\String('I ❤ Unicode');\n$maths = new Hoa\\String\\String('∀ i ∈ ℕ');\n\necho\n    $emoji-\u003etoAscii(), \"\\n\",\n    $maths-\u003etoAscii(), \"\\n\";\n\n/**\n * Will output:\n *     I (heavy black heart) Unicode\n *     (for all) i (element of) N\n */\n```\n\n### Search algorithm\n\nThe `Hoa\\String\\Search` implements search algorithms on strings.\n\nFor example, the `Hoa\\String\\Search::approximated` method make a search by\napproximated patterns (with *k* differences based upon the principle diagonal\nmonotony). If we search the word `GATAA` in `CAGATAAGAGAA` with 1 difference, we\nwill do:\n\n```php\n$search = Hoa\\String\\Search::approximated(\n    $haystack = 'CAGATAAGAGAA',\n    $needle   = 'GATAA',\n    $k        = 1\n);\n$solutions = array();\n\nforeach ($search as $pos) {\n    $solutions[] = substr($haystack, $pos['i'], $pos['l']);\n}\n```\n\nWe will found `AGATA`, `GATAA`, `ATAAG` and `GAGAA`.\n\nThe result is not very handy but the algorithm is much optimized and found many\napplications.\n\n## Documentation\n\nDifferent documentations can be found on the website:\n[http://hoa-project.net/](http://hoa-project.net/).\n\n## License\n\nHoa is under the New BSD License (BSD-3-Clause). Please, see\n[`LICENSE`](http://hoa-project.net/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoaproject%2FString","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhoaproject%2FString","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoaproject%2FString/lists"}