{"id":16973978,"url":"https://github.com/henrik9999/string-similarity","last_synced_at":"2025-10-20T11:17:55.463Z","repository":{"id":37485926,"uuid":"505120559","full_name":"henrik9999/string-similarity","owner":"henrik9999","description":"Finds degree of similarity between two strings, based on Dice's Coefficient, which is mostly better than Levenshtein distance.","archived":false,"fork":false,"pushed_at":"2023-11-23T16:14:18.000Z","size":12,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-25T05:01:31.199Z","etag":null,"topics":["dice-coefficient","php","php8","string","string-comparison","string-distance","string-distance-calculation","string-similarity","strings"],"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/henrik9999.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-19T13:40:07.000Z","updated_at":"2022-08-14T17:08:42.000Z","dependencies_parsed_at":"2024-10-14T01:04:12.924Z","dependency_job_id":"f03c03eb-d9cf-43ea-b0bd-3117f24e8189","html_url":"https://github.com/henrik9999/string-similarity","commit_stats":{"total_commits":5,"total_committers":1,"mean_commits":5.0,"dds":0.0,"last_synced_commit":"b0933486177a445e0439c3d7470a8a829d8582c4"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henrik9999%2Fstring-similarity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henrik9999%2Fstring-similarity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henrik9999%2Fstring-similarity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henrik9999%2Fstring-similarity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/henrik9999","download_url":"https://codeload.github.com/henrik9999/string-similarity/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248961236,"owners_count":21189993,"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":["dice-coefficient","php","php8","string","string-comparison","string-distance","string-distance-calculation","string-similarity","strings"],"created_at":"2024-10-14T01:04:10.621Z","updated_at":"2025-10-20T11:17:55.330Z","avatar_url":"https://github.com/henrik9999.png","language":"PHP","readme":"# string-similarity\n\nFinds degree of similarity between two strings, based on [Dice's Coefficient](http://en.wikipedia.org/wiki/S%C3%B8rensen%E2%80%93Dice_coefficient), which is mostly better than [Levenshtein distance](http://en.wikipedia.org/wiki/Levenshtein_distance).\n\nThis implementation actually treats multiple occurrences of a bigram as unique. The correctness of this behavior is most easily seen when getting the similarity between \"GG\" and \"GGGGGGGG\", which should obviously not be 1.\n\nThis is a PHP implemenation of the Node.js package [string-similarity](https://github.com/aceakash/string-similarity)\n\n## Usage\nInstall using:\n\n```shell\ncomposer require henrik9999/string-similarity\n```\n\nIn your code:\n\n```php\n$stringSimilarity = new StringSimilarity();\n\n$similarity = $stringSimilarity-\u003ecompareTwoStrings(\"healed\", \"sealed\");\n\n$matches = $stringSimilarity-\u003efindBestMatch(\"healed\", [\n  \"edward\",\n  \"sealed\",\n  \"theatre\",\n]);\n```\n\n## API\n\nThe package contains two methods:\n\n### compareTwoStrings(string $string1, string $string2, bool $casesensitive)\n\nReturns a fraction between 0 and 1, which indicates the degree of similarity between the two strings. 0 indicates completely different strings, 1 indicates identical strings. The comparison is case-sensitive by default.\n\n##### Arguments\n\n1. string1 (string): The first string\n2. string2 (string): The second string\n2. casesensitive (bool): If the comparison should be case-sensitive\n\nOrder does not make a difference.\n\n##### Returns\n\n(number): A fraction from 0 to 1, both inclusive. Higher number indicates more similarity.\n\n##### Examples\n\n```php\n$stringSimilarity-\u003ecompareTwoStrings(\"healed\", \"sealed\");\n// → 0.8\n\n$stringSimilarity-\u003ecompareTwoStrings(\n  \"Olive-green table for sale, in extremely good condition.\",\n  \"For sale: table in very good  condition, olive green in colour.\"\n);\n// → 0.6060606060606061\n\n$stringSimilarity-\u003ecompareTwoStrings(\n  \"Olive-green table for sale, in extremely good condition.\",\n  \"For sale: green Subaru Impreza, 210,000 miles\"\n);\n// → 0.2558139534883721\n\n$stringSimilarity-\u003ecompareTwoStrings(\n  \"Olive-green table for sale, in extremely good condition.\",\n  \"Wanted: mountain bike with at least 21 gears.\"\n);\n// → 0.1411764705882353\n```\n\n### findBestMatch(string mainString, array targetStrings, bool $casesensitive)\n\nCompares `mainString` against each string in `targetStrings`.\n\n##### Arguments\n\n1. mainString (string): The string to match each target string against.\n2. targetStrings (array): Each string in this array will be matched against the main string.\n3. casesensitive (bool): If the comparison should be case-sensitive.\n\n##### Returns\n\n(Object): An object with a `ratings` property, which gives a similarity rating for each target string, a `bestMatch` property, which specifies which target string was most similar to the main string, and a `bestMatchIndex` property, which specifies the index of the bestMatch in the targetStrings array.\n\n##### Examples\n\n```php\n$stringSimilarity-\u003efindBestMatch('Olive-green table for sale, in extremely good condition.', [\n  'For sale: green Subaru Impreza, 210,000 miles',\n  'For sale: table in very good condition, olive green in colour.',\n  'Wanted: mountain bike with at least 21 gears.'\n]);\n// →\narray(3) {\n  [\"ratings\"]=\u003e\n  array(3) {\n    [0]=\u003e\n    array(2) {\n      [\"target\"]=\u003e\n      string(45) \"For sale: green Subaru Impreza, 210,000 miles\"\n      [\"rating\"]=\u003e\n      float(0.2558139534883721)\n    }\n    [1]=\u003e\n    array(2) {\n      [\"target\"]=\u003e\n      string(62) \"For sale: table in very good condition, olive green in colour.\"\n      [\"rating\"]=\u003e\n      float(0.6060606060606061)\n    }\n    [2]=\u003e\n    array(2) {\n      [\"target\"]=\u003e\n      string(45) \"Wanted: mountain bike with at least 21 gears.\"\n      [\"rating\"]=\u003e\n      float(0.1411764705882353)\n    }\n  }\n  [\"bestMatch\"]=\u003e\n  array(2) {\n    [\"target\"]=\u003e\n    string(62) \"For sale: table in very good condition, olive green in colour.\"\n    [\"rating\"]=\u003e\n    float(0.6060606060606061)\n  }\n  [\"bestMatchIndex\"]=\u003e\n  int(1)\n}\n```\n\n## Release Notes\n\n### 1.0.1\n- Made some perfomance improvements\n\n### 1.0.0\n- Initial Release","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhenrik9999%2Fstring-similarity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhenrik9999%2Fstring-similarity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhenrik9999%2Fstring-similarity/lists"}