PHP Classes

How can PHP calculate the similarity between two strings using different algorithm with the package Fuzzion: Get string similarity using different algorithms

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2025-10-27 (5 hours ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
fuzzion 1.0.0Artistic License5PHP 5, Text processing, Artificial in...
Description 

Author

This package can get string similarity using different algorithms.

It provides a class with functions that can compare two strings and return a similarity level number calculated using different algorithms.

The package provides the same function in PHP, JavaScript and Python.

Picture of Nikos M.
Name: Nikos M. is available for providing paid consulting. Contact Nikos M. .
Classes: 22 packages by
Country: Greece Greece
Age: 49
All time rank: 8449 in Greece Greece
Week rank: 195 Up2 in Greece Greece Up
Innovation award
Innovation award
Nominee: 8x

Winner: 2x

Instructions

Please read this document to learn how to use a PHP class to get the similarity between two strings.

Example

<?php
include(dirname(__FILE__) . '/../../src/php/Fuzzion.php');

function
test()
{
   
$matcher = new Fuzzion();
   
$tests = [
    [
'jointure', 'join'],
    [
'jointure', 'jiontre'],
    [
'jointure', 'joitnrue'],
    [
'jointure', 'turejoin'],
    ];

    foreach (
$tests as $test)
    {
       
$string1 = $test[0];
       
$string2 = $test[1];
        echo
"\n"; echo('levenshtein("'.$string1.'", "'.$string2.'") = '.strval($matcher->levenshtein($string1, $string2)));
        echo
"\n"; echo('damerau("'.$string1.'", "'.$string2.'") = '.strval($matcher->damerau($string1, $string2)));
        echo
"\n"; echo('lcs("'.$string1.'", "'.$string2.'") = '.strval($matcher->lcs($string1, $string2)));
        echo
"\n"; echo('jaccard("'.$string1.'", "'.$string2.'") = '.strval($matcher->jaccard($string1, $string2)));
        echo
"\n"; echo('overlap("'.$string1.'", "'.$string2.'") = '.strval($matcher->overlap($string1, $string2)));
        echo
"\n"; echo('hamming("'.$string1.'", "'.$string2.'") = '.strval($matcher->hamming($string1, $string2)));
        echo
"\n"; echo('jaro("'.$string1.'", "'.$string2.'") = '.strval($matcher->jaro($string1, $string2)));
        echo
"\n"; echo('ngram("'.$string1.'", "'.$string2.'", 2) = '.strval($matcher->ngram($string1, $string2, 2)));
        echo
"\n"; echo('ngram("'.$string1.'", "'.$string2.'", 3) = '.strval($matcher->ngram($string1, $string2, 3)));
        echo
"\n";
    }
}

test();


Details

Fuzzion

Fuzzy / approximate string similarity metrics for PHP, JavaScript, Python

Fuzzion

version: 1.0.0

Included Metrics:

examples:

see test/ folder

levenshtein("jointure", "join") = 0.5
damerau("jointure", "join") = 0.5
lcs("jointure", "join") = 0.5
jaccard("jointure", "join") = 0.5
overlap("jointure", "join") = 1
hamming("jointure", "join") = 0.5
jaro("jointure", "join") = 0.9
ngram("jointure", "join", 2) = 0.6
ngram("jointure", "join", 3) = 0.5

levenshtein("jointure", "jiontre") = 0.625
damerau("jointure", "jiontre") = 0.75
lcs("jointure", "jiontre") = 0.625
jaccard("jointure", "jiontre") = 0.875
overlap("jointure", "jiontre") = 1
hamming("jointure", "jiontre") = 0.375
jaro("jointure", "jiontre") = 0.91964285714286
ngram("jointure", "jiontre", 2) = 0.30769230769231
ngram("jointure", "jiontre", 3) = 0

levenshtein("jointure", "joitnrue") = 0.625
damerau("jointure", "joitnrue") = 0.75
lcs("jointure", "joitnrue") = 0.5
jaccard("jointure", "joitnrue") = 1
overlap("jointure", "joitnrue") = 1
hamming("jointure", "joitnrue") = 0.5
jaro("jointure", "joitnrue") = 0.94166666666667
ngram("jointure", "joitnrue", 2) = 0.28571428571429
ngram("jointure", "joitnrue", 3) = 0.16666666666667

levenshtein("jointure", "turejoin") = 0
damerau("jointure", "turejoin") = 0
lcs("jointure", "turejoin") = 0
jaccard("jointure", "turejoin") = 1
overlap("jointure", "turejoin") = 1
hamming("jointure", "turejoin") = 0
jaro("jointure", "turejoin") = 0
ngram("jointure", "turejoin", 2) = 0
ngram("jointure", "turejoin", 3) = 0

see also:

  • Abacus Computer Algebra and Symbolic Computation System for Combinatorics and Algebraic Number Theory for JavaScript and Python
  • TensorView view array data as multidimensional tensors of various shapes efficiently
  • Geometrize Computational Geometry and Rendering Library for JavaScript
  • Plot.js simple and small library which can plot graphs of functions and various simple charts and can render to Canvas, SVG and plain HTML
  • CanvasLite an html canvas implementation in pure JavaScript
  • Rasterizer stroke and fill lines, rectangles, curves and paths, without canvas
  • Gradient create linear, radial, conic and elliptic gradients and image patterns without canvas
  • css-color simple class to parse and manipulate colors in various formats
  • MOD3 3D Modifier Library in JavaScript
  • HAAR.js image feature detection based on Haar Cascades in JavaScript (Viola-Jones-Lienhart et al Algorithm)
  • HAARPHP image feature detection based on Haar Cascades in PHP (Viola-Jones-Lienhart et al Algorithm)
  • FILTER.js video and image processing and computer vision Library in pure JavaScript (browser and node)
  • Xpresion a simple and flexible eXpression parser engine (with custom functions and variables support), based on GrammarTemplate, for PHP, JavaScript, Python
  • Regex Analyzer/Composer Regular Expression Analyzer and Composer for PHP, JavaScript, Python
  • GrammarTemplate grammar-based templating for PHP, JavaScript, Python
  • codemirror-grammar transform a formal grammar in JSON format into a syntax-highlight parser for CodeMirror editor
  • ace-grammar transform a formal grammar in JSON format into a syntax-highlight parser for ACE editor
  • prism-grammar transform a formal grammar in JSON format into a syntax-highlighter for Prism code highlighter
  • highlightjs-grammar transform a formal grammar in JSON format into a syntax-highlight mode for Highlight.js code highlighter
  • syntaxhighlighter-grammar transform a formal grammar in JSON format to a highlight brush for SyntaxHighlighter code highlighter
  • Fuzzion a library of fuzzy / approximate string metrics for PHP, JavaScript, Python
  • Matchy a library of string matching algorithms for PHP, JavaScript, Python
  • PatternMatchingAlgorithms library of Pattern Matching Algorithms in JavaScript using Matchy
  • SortingAlgorithms library of Sorting Algorithms in JavaScript

  Files folder image Files (13)  
File Role Description
Files folder imagesrc (3 directories)
Files folder imagetest (3 directories)
Accessible without login Image file fuzzion.png Icon Icon image
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (13)  /  src  
File Role Description
Files folder imagejs (2 files)
Files folder imagephp (1 file)
Files folder imagepy (2 files)

  Files folder image Files (13)  /  src  /  js  
File Role Description
  Accessible without login Plain text file Fuzzion.js Data Auxiliary data
  Accessible without login Plain text file Fuzzion.min.js Data Auxiliary data

  Files folder image Files (13)  /  src  /  php  
File Role Description
  Plain text file Fuzzion.php Class Class source

  Files folder image Files (13)  /  src  /  py  
File Role Description
  Accessible without login Plain text file Fuzzion.py Data Auxiliary data
  Accessible without login Plain text file __init__.py Data Auxiliary data

  Files folder image Files (13)  /  test  
File Role Description
Files folder imagejs (2 files)
Files folder imagephp (2 files)
Files folder imagepy (2 files)

  Files folder image Files (13)  /  test  /  js  
File Role Description
  Accessible without login Plain text file out.txt Doc. Documentation
  Accessible without login Plain text file test.js Data Auxiliary data

  Files folder image Files (13)  /  test  /  php  
File Role Description
  Accessible without login Plain text file out.txt Doc. Documentation
  Accessible without login Plain text file test.php Example Example script

  Files folder image Files (13)  /  test  /  py  
File Role Description
  Accessible without login Plain text file out.txt Doc. Documentation
  Accessible without login Plain text file test.py Data Auxiliary data

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads  
 100%
Total:0
This week:0