PHP code example of rap2hpoutre / similar-text-finder
1. Go to this page and download the library: Download rap2hpoutre/similar-text-finder 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/ */
rap2hpoutre / similar-text-finder example snippets
// Init Similar Text Finder with a needle and a haystack
$text_finder = new \SimilarText\Finder('bananna', ['apple', 'banana', 'kiwi']);
// Get first similar word (it's banana)
echo $text_finder->first();
$tf = new \SimilarText\Finder($needle, $haystack);
echo 'Did you mean ' $tf->first() . ' ?';
$all = $tf->all();
use SimilarText\Finder;
// User input with a typo (you could get it from $_GET)
$needle = 'tmatoes';
// Your list (from your database or an API)
$haystack = ['salad', 'tomatoes', 'onions', 'mates'];
// Init Text Finder
$finder = new Finder($needle, $haystack);
// Display all results ordered by the most approching
$results = $finder->all();
echo implode(', ', $results);
// You should see something like "tomatoes, mates, onions, salad", yohoo.
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.