Last Updated | | Ratings | | Unique User Downloads | | Download Rankings |
2023-11-01 (2 months ago) | | Not yet rated by the users | | Total: 46 | | All time: 10,660 This week: 175 |
|
Description | | Author |
This package can compare strings and return a similarity score.
It can take two strings as parameters and create arrays with the codes of each character of the strings.
The class can compare the two arrays of string character codes and return a number that is the hammering distance and represents a value that determines how similar the two strings are. | |
|
|
Innovation award
Nominee: 1x |
|
Example
<?php
spl_autoload_register(function ($class) {
include $class . '.class.php';
});
/* examples */
/* string mode off for letter by letter comparison */
// int(0) the same text
var_dump(stringDifference::hammeringDistance('The quick brown fox jumps over the lazy dog','The quick brown fox jumps over the lazy dog'));
// int(1) one letter difference
var_dump(stringDifference::hammeringDistance('The quick brown fex jumps over the lazy dog','The quick brown fox jumps over the lazy dog'));
// int(1) there is a space at the end of the first string
var_dump(stringDifference::hammeringDistance('The quick brown fox jumps over the lazy dog ','The quick brown fox jumps over the lazy dog'));
/* bin mode on for bit by bit comparison */
// int(0) the same text
var_dump(stringDifference::hammeringDistance('The quick brown fox jumps over the lazy dog','The quick brown fox jumps over the lazy dog',true));
// int(2) one letter difference
var_dump(stringDifference::hammeringDistance('The quick brown fex jumps over the lazy dog','The quick brown fox jumps over the lazy dog',true));
// int(8) there is a space at the end of the first string
var_dump(stringDifference::hammeringDistance('The quick brown fox jumps over the lazy dog ','The quick brown fox jumps over the lazy dog',true));
|
Details
simple-string-comparison
Less simple than strcmp. Compare strings letter by letter or bit by bit
It returns an int value representing the difference between two strings. For example, it gives a more precise difference between uppercase and lowercase letters, so you can decide if there is a typo between two strings. There are also letter-by-letter and binary comparisons.
Use it like this:
Letter by letter mode: This will return 1 as one letter is different (in the word fox there is a typo).
echo stringDifference::hammeringDistance('The quick brown fex jumps over the lazy dog','The quick brown fox jumps over the lazy dog')
Binary mode:
This will return 2 because in binary mode the distance between the e and o in the two sentences is 2.
echo stringDifference::hammeringDistance('The quick brown fex jumps over the lazy dog','The quick brown fox jumps over the lazy dog',true));
|
Applications that use this package |
|
No pages of applications that use this class were specified.
If you know an application of this package, send a message to the author to add a link here.