PHP code example of keinos / mb_levenshtein

1. Go to this page and download the library: Download keinos/mb_levenshtein library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

keinos / mb_levenshtein example snippets


    mb_levenshtein ( string $str1 , string $str2 ) : int
    

    mb_levenshtein ( string $str1 , string $str2 , int $cost_ins , int $cost_rep , int $cost_del ) : int
    

    mb_levenshtein_ratio ( string $str1 , string $str2 ) : float
    

    mb_levenshtein_ratio ( string $str1 , string $str2 , int $cost_ins , int $cost_rep , int $cost_del ) : float
    


ry = 'cafe';
$comps = [
    'coffee',
    'café',
    'tea',
    'sake',
];

echo "Query word: ${query}" . PHP_EOL;

foreach ($comps as $comp) {
    $sim = mb_levenshtein($query, $comp);
    echo "  ${comp}: ${sim}" . PHP_EOL;
}


ry = 'cafe';
$comps = [
    'coffee',
    'café',
    'tea',
    'sake',
];

echo "Query word: ${query}" . PHP_EOL;

foreach ($comps as $comp) {
    $sim = mb_levenshtein($query, $comp);
    echo "  ${comp}: ${sim}" . PHP_EOL;
}
shellsession
$ # The smaller, the closer
$ php ./sample.php
Query word: cafe
  coffee: 3
  café: 1
  tea: 4
  sake: 2
shellsession
$ ls
sample.php
$ composer shtein
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including The smaller, the closer
$ php ./sample.php
Query word: cafe
  coffee: 3
  café: 1
  tea: 4
  sake: 2
$ ls
composer.json   composer.lock   sample.php  vendor
$ cat composer.json
{
    "