1. Go to this page and download the library: Download nullform/fuzzio 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/ */
nullform / fuzzio example snippets
use \Nullform\Fuzzio\Fuzzio;
use \Nullform\Fuzzio\FuzzioString;
$needle = 'john'; // Reference string
$haystack = ['jon', 'johns', 'jane', 'janie']; // Array of strings
$fuzzio = new Fuzzio($needle, $haystack);
// Get all strings from $haystack with calculated similarity and Levenshtein distance
$all = $fuzzio->get(); // FuzzioString[]
// Get strings with similarity >= 80% and Levenshtein distance <= 1
$filtered = $fuzzio->get(80, 1); // FuzzioString[]
// Get strings with Levenshtein distance <= 1
$filtered = $fuzzio->get(null, 1); // FuzzioString[]
// With max similarity value
$allClosest = $fuzzio->getClosest(); // FuzzioString[]
// One (first) with max similarity value
$closestOne = $fuzzio->getClosestOne(); // FuzzioString
echo $closestOne; // johns
echo $closestOne->getString(); // johns
echo $closestOne->getSimilarity(); // 88.888888888889
echo $closestOne->getLevenshteinDistance(); // 1
echo $fuzzio->getMaxSimilarity(); // 88.888888888889
// Is there an exact match in the collection
$fuzzio->hasExactMatch(); // false
// Add string to haystack
$fuzzio->addToHaystack(['julie']);
// Remove strings from haystack
$fuzzio->removeFromHaystack(['janie', 'julie']);
use \Nullform\Fuzzio\Fuzzio;
$needle = 'john'; // Reference string
$haystack = ['jon', 'johns', 'jane', 'janie']; // Array of strings
$fuzzio = new Fuzzio($needle);
// Set max Levenshtein distance threshold
$fuzzio->setMaxLevenshteinDistanceThreshold(1);
// Set min similarity threshold
$fuzzio->setMinSimilarityThreshold(80);
// Set array of strings to calculate similarity
$fuzzio->setHaystack($haystack);
// Get strings with similarity >= 80% and Levenshtein distance <= 1
$collection = $fuzzio->get();
use \Nullform\Fuzzio\Fuzzio;
$needle = 'John'; // Reference string
$haystack = ['Jon ', 'Johns', 'JANE', 'Janie']; // Array of strings
$normalizer = function ($string) {
return trim(strtolower($string));
};
$fuzzio = new Fuzzio($needle);
// Normalizer for $needle and $haystack
$fuzzio->setNormalizer($normalizer);
// Set array of strings to calculate similarity
$fuzzio->setHaystack($haystack);
// Or like this
$fuzzio = new Fuzzio($needle, $haystack, $normalizer);
echo $fuzzio->getNeedle(); // John
echo $fuzzio->getNormalizedNeedle(); // john
// One with max similarity
$closest = $fuzzio->getClosestOne();
echo $closest; // Johns
echo $closest->getString(); // Johns
echo $closest->getNormalizedString(); // johns
echo $closest->getSimilarity(); // 88.888888888889
echo $closest->getLevenshteinDistance(); // 1
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.