note 125682 added to function.levenshtein
| From: | phpcoder at gmail dot com | Date: | Fri, 15 Jan 2021 10:43:52 +0000 |
| Subject: | note 125682 added to function.levenshtein | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-216161@lists.php.net to get a copy of this message | ||
@Digeridoo
$levenshtein = levenshtein($a, $b/*, 1, 1, 1*/);
The easiest way (the one with minimum cost) to convert "1 apple" to "2 apples"
is to replace "1" with "2" (at a cost of 1), and then insert an "s"
(at a cost of 1). The total cost is therefore 2.
$inserts = levenshtein($a, $b, 1, 0, 0);
Again, we replace "1" with "2" and insert an 's'. The insertion has a
cost of 1, and the replacement has a cost of 0; the total cost is 1.
$deletes = levenshtein($a, $b, 0, 0, 1);
Replacing "1" with "2" has zero cost, and so does inserting an "s";
the total cost of converting "1 apple" to "2 apples" is 0.
$replaces = levenshtein($a, $b, 0, 1, 0);
Easiest thing to do here is just delete everything and insert all-new text. Both have zero cost, so
the total cost is 0.
----
Server IP: 45.112.84.4
Probable Submitter: 101.0.109.162 (proxied: 125.239.154.159)
----
Manual Page -- http://php.net/manual/en/function.levenshtein.php
Edit -- https://master.php.net/note/edit/125682
Del: integrated -- https://master.php.net/note/delete/125682/integrated
Del: useless -- https://master.php.net/note/delete/125682/useless
Del: bad code -- https://master.php.net/note/delete/125682/bad+code
Del: spam -- https://master.php.net/note/delete/125682/spam
Del: non-english -- https://master.php.net/note/delete/125682/non-english
Del: in docs -- https://master.php.net/note/delete/125682/in+docs
Del: other reasons-- https://master.php.net/note/delete/125682
Reject -- https://master.php.net/note/reject/125682
Search -- https://master.php.net/manage/user-notes.php