{"id":15025845,"url":"https://github.com/jfcherng/php-levenshtein-distance","last_synced_at":"2025-04-09T20:03:56.686Z","repository":{"id":56998615,"uuid":"138482061","full_name":"jfcherng/php-levenshtein-distance","owner":"jfcherng","description":"Calculates the Levenshtein distance and the edit progresses between two strings.","archived":false,"fork":false,"pushed_at":"2024-11-06T20:52:36.000Z","size":208,"stargazers_count":2,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T20:03:50.975Z","etag":null,"topics":["edit-distance","edit-progress","levenshtein-distance","php-71","psr-1","psr-2","psr-4"],"latest_commit_sha":null,"homepage":null,"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/jfcherng.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":"https://www.paypal.me/jfcherng/5usd"}},"created_at":"2018-06-24T12:59:17.000Z","updated_at":"2023-02-07T14:46:17.000Z","dependencies_parsed_at":"2023-01-29T15:45:40.221Z","dependency_job_id":null,"html_url":"https://github.com/jfcherng/php-levenshtein-distance","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jfcherng%2Fphp-levenshtein-distance","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jfcherng%2Fphp-levenshtein-distance/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jfcherng%2Fphp-levenshtein-distance/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jfcherng%2Fphp-levenshtein-distance/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jfcherng","download_url":"https://codeload.github.com/jfcherng/php-levenshtein-distance/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248103864,"owners_count":21048245,"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":["edit-distance","edit-progress","levenshtein-distance","php-71","psr-1","psr-2","psr-4"],"created_at":"2024-09-24T20:03:08.349Z","updated_at":"2025-04-09T20:03:56.660Z","avatar_url":"https://github.com/jfcherng.png","language":"PHP","funding_links":["https://www.paypal.me/jfcherng/5usd"],"categories":[],"sub_categories":[],"readme":"# php-levenshtein-distance\n\n[![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/jfcherng/php-levenshtein-distance/php.yml?branch=master\u0026style=flat-square)](https://github.com/jfcherng/php-levenshtein-distance/actions)\n[![Packagist](https://img.shields.io/packagist/dt/jfcherng/php-levenshtein-distance?style=flat-square)](https://packagist.org/packages/jfcherng/php-levenshtein-distance)\n[![Packagist Version](https://img.shields.io/packagist/v/jfcherng/php-levenshtein-distance?style=flat-square)](https://packagist.org/packages/jfcherng/php-levenshtein-distance)\n[![Project license](https://img.shields.io/github/license/jfcherng/php-levenshtein-distance?style=flat-square)](https://github.com/jfcherng/php-levenshtein-distance/blob/master/LICENSE)\n[![GitHub stars](https://img.shields.io/github/stars/jfcherng/php-levenshtein-distance?style=flat-square\u0026logo=github)](https://github.com/jfcherng/php-levenshtein-distance/stargazers)\n[![Donate to this project using Paypal](https://img.shields.io/badge/paypal-donate-blue.svg?style=flat-square\u0026logo=paypal)](https://www.paypal.me/jfcherng/5usd)\n\nCalculate the Levenshtein distance and edit progresses between two strings.\nNote that if you do not need the edit path, PHP has a built-in [levenshtein()](http://php.net/manual/en/function.levenshtein.php) function.\n\n\n## Features\n\n- UTF-8-ready.\n- Full edit progresses information.\n\n\n## Installation\n\n```bash\n$ composer require jfcherng/php-levenshtein-distance\n```\n\n\n## Example\n\nSee `demo.php`.\n\n```php\n\u003c?php\n\ninclude __DIR__ . '/vendor/autoload.php';\n\nuse Jfcherng\\Diff\\LevenshteinDistance as LD;\n\n$old = '自訂取代詞語模組';\n$new = '自订取代词语模组！';\n\n$calculator = new LD(\n    true, // calculate edit progresses?\n    // progress options\n    LD::PROGRESS_OP_AS_STRING | LD::PROGRESS_PATCH_MODE\n);\n\n$results = $calculator-\u003ecalculate($old, $new);\n\n// this is the same but using an internal singleton\n$results = LD::staticCalculate(\n    $old, // old string\n    $new, // new string\n    true, // calculate edit progresses?\n    // progress options\n    LD::PROGRESS_OP_AS_STRING | LD::PROGRESS_PATCH_MODE\n);\n\n// [\n//     'distance' =\u003e 5,\n//     'progresses' =\u003e [\n//         ['ins', 8, '！', 1],\n//         ['rep', 7, '组', 1],\n//         ['cpy', 6, '模', 1],\n//         ['rep', 5, '语', 1],\n//         ['rep', 4, '词', 1],\n//         ['cpy', 3, '代', 1],\n//         ['cpy', 2, '取', 1],\n//         ['rep', 1, '订', 1],\n//         ['cpy', 0, '自', 1],\n//     ],\n// ]\nvar_dump($results);\n\n$results = LD::staticCalculate(\n    $old, // old string\n    $new, // new string\n    true, // calculate edit progresses?\n    // progress options\n    LD::PROGRESS_OP_AS_STRING | LD::PROGRESS_PATCH_MODE | LD::PROGRESS_MERGE_NEIGHBOR\n);\n\n// [\n//     'distance' =\u003e 5,\n//     'progresses' =\u003e [\n//         ['ins', 8, '！', 1],\n//         ['rep', 7, '组', 1],\n//         ['cpy', 6, '模', 1],\n//         ['rep', 4, '词语', 2],\n//         ['cpy', 2, '取代', 2],\n//         ['rep', 1, '订', 1],\n//         ['cpy', 0, '自', 1],\n//     ],\n// ]\nvar_dump($results);\n```\n\n\n## Progress Options\n\n- `LD::PROGRESS_NO_COPY`: Do not include `COPY` operations in the progresses.\n- `LD::PROGRESS_MERGE_NEIGHBOR`: Merge neighbor progresses if possible.\n- `LD::PROGRESS_OP_AS_STRING`: Convert the operation in progresses from int to string.\n- `LD::PROGRESS_PATCH_MODE`: Replace the new edit position with the corresponding string.\n\n\n## Returned `progresses`\n\n1. The operation.\n1. The edit position for the new string.\n1. The edit position for the old string.\n   Or the corresponding string if `LD::PROGRESS_PATCH_MODE` is used.\n1. The edit length.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjfcherng%2Fphp-levenshtein-distance","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjfcherng%2Fphp-levenshtein-distance","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjfcherng%2Fphp-levenshtein-distance/lists"}